Java 在JFileChooser中重命名文件而不使用inputDialog

Java 在JFileChooser中重命名文件而不使用inputDialog,java,swing,user-interface,awt,jfilechooser,Java,Swing,User Interface,Awt,Jfilechooser,我已经用Java编写了一个GUI,它允许您保存一个文件。在JFilechooser窗口中,您还可以重命名、删除或创建新文件。到目前为止,始终会打开一个新的inputDialog来输入文件的新名称。 如何在JFileChooser窗口本身中输入新文件的名称,而不打开新的JOptionPane Inputdialog 非常感谢 private void contextMenu() { try { popup = new JPopupMenu();

我已经用Java编写了一个GUI,它允许您保存一个文件。在JFilechooser窗口中,您还可以重命名、删除或创建新文件。到目前为止,始终会打开一个新的inputDialog来输入文件的新名称。 如何在JFileChooser窗口本身中输入新文件的名称,而不打开新的JOptionPane Inputdialog

非常感谢

private void contextMenu() {
        try {
            popup = new JPopupMenu();
            ActionListener menuListener = new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
                    if (event.getActionCommand().equals("Delete")) {
                        // your logic here
                        File file = fc.getSelectedFile();
                        if (file != null) {
                            if (askConfirm() == JOptionPane.YES_OPTION) {
                                try {
                                    String deleted = file.getName();
                                    String location = file.getParent();
                                    Files.delete(file.toPath());
                                    log.info("Deleted " + deleted + " in the directory " + location);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                fc.rescanCurrentDirectory();
                            }
                        }
                    } else if (event.getActionCommand().equals("Rename")) {
                        File file = fc.getSelectedFile();
                        String path = file.getParent();

                        String rename = JOptionPane.showInputDialog("Please enter name:");
                        if (file.exists()) {
                            String oldName = file.getName();
                            file.renameTo(new File(path + "/" + rename));
                            String newName = file.getName();
                            String directory = file.getParent();
                            log.info("Changed the name from " + oldName + " to " + newName + " in the directory "
                                    + directory);
                        }
                        fc.rescanCurrentDirectory();
                    } else if (event.getActionCommand().equals("New Folder")) {
                        File file = fc.getCurrentDirectory();
                        String path = file.getPath();
                        String directory = file.getParent();
                        String name = JOptionPane.showInputDialog("Please enter name:");
                        name = name.equals("") || name.equals(null) ? "Unbenannt" : name;
                        boolean dir = new File(path + "/" + name).mkdir();
                        if (dir) {
                            log.info("Created Directory " + name + " in the directory " + directory);
                        }
                        fc.rescanCurrentDirectory();
                    }
                }
            };