Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入键不在JFileChoose中工作在Java 7中_Java_Jfilechooser - Fatal编程技术网

输入键不在JFileChoose中工作在Java 7中

输入键不在JFileChoose中工作在Java 7中,java,jfilechooser,Java,Jfilechooser,在使用JFileChooser for Java 7时,我遇到了一个问题。当我在目录上单击enter键(目录浏览)时,我没有看到任何操作,按键被忽略。 下面是我的代码实现 public static void main(String[] a) { JFrame frame = new JFrame("JFileChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JFileChoos

在使用JFileChooser for Java 7时,我遇到了一个问题。当我在目录上单击enter键(目录浏览)时,我没有看到任何操作,按键被忽略。 下面是我的代码实现

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    frame.add(fileChooser, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println(actionEvent.getSource());
        JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
        String command = actionEvent.getActionCommand();
        if (command.equals(JFileChooser.APPROVE_SELECTION)) {
          File selectedFile = theFileChooser.getSelectedFile();
          System.out.println(selectedFile.getParent());
          System.out.println(selectedFile.getName());
        } else if (command.equals(JFileChooser.CANCEL_SELECTION)) {
          System.out.println(JFileChooser.CANCEL_SELECTION);
        }
      }
    };
    fileChooser.addActionListener(actionListener);
    frame.pack();
    frame.setVisible(true);
  }
}
非常感谢您的帮助


如果您删除
文件选择器.setControlButtonsAreShown(false),请感谢行,输入按钮将工作


加上。。。。您的用户将能够使用他们希望在对话框中看到的普通按钮

您好,谢谢您的回复。我删除了行文件选择器。setControlButtonsAreShown(false);但是没有运气:(