【发布时间】:2017-10-21 05:34:50
【问题描述】:
我正在运行一个分析数据的 java 程序,这是我编写的。当我尝试加载数据文件时,JFileChooser 正常打开,但我无法双击文件夹来更改工作目录。其他人遇到这个问题,有解决方法吗?不知道是java、eclipse、mac还是组合问题。
我在 mac 10.12.6 (Sierra) java 1.8.0_121 上运行 eclipse (Oxygen)
这是 SSCE 的主要内容。
public static void main(String[] args) {
JFileChooser fileChooser = new JFileChooser(".");
int status = fileChooser.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
System.out.println(selectedFile.getParent());
System.out.println(selectedFile.getName());
} else if (status == JFileChooser.CANCEL_OPTION) {
System.out.println("canceled");
}
}
谢谢
【问题讨论】:
-
仅供参考 - 已检查您的代码,它适用于我在 Windows 上。您也可以尝试使用here 中提到的外观和感觉吗
-
还有一个here
-
目录的权限呢?
-
我不知道这是否是你的问题的原因,但它可能,而且无论如何它是极其重要的:do not run Swing code from the initial thread, always manipulate your user interface from the event dispatch thread
-
Mikita,它在 Windows 上运行良好。我试过玩 X11 服务器,java 不应该接触它(大多数时候我什至不启动 X11 服务器)。我把 L&F 改成了 X 平台的 L&F,效果好一点(有时我必须双击多次,很烦人)。
标签: java jfilechooser