输入键不在JFileChoose中工作在Java 7中
在使用JFileChooser for Java 7时,我遇到了一个问题。当我在目录上单击enter键(目录浏览)时,我没有看到任何操作,按键被忽略。 下面是我的代码实现输入键不在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
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);但是没有运气:(