我似乎对我的文件选择器对话的非常简单的实现有一个问题,这需要我每次都要最小化Netbeans才能到达它,并且特别是现在通过测试它变得非常令人沮丧.
我已经在网上看到了一些解决方案,包括SO,但似乎没有一个可以做到这一点,而其他一些解决方案对我目前的水平看起来非常冗长和复杂.
private void fileSearch() {
JFileChooser fileSelect = new JFileChooser();
int returnVal = fileSelect.showOpenDialog(null);
String pathToFile;
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileSelect.getSelectedFile();
pathToFile = file.getAbsolutePath();
try {
P.binaryFileToHexString(pathToFile);
} catch (Exception e) {
System.out.print("Oops! there was an error there..." + e);
}
System.out.println("\nYou chose to open this file: " + file.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
我的一些尝试包括使用;
.requestFocus();
.requestFocusInWindow();
.setVisible();
Run Code Online (Sandbox Code Playgroud)
我可以设置一个特定的属性/方法来解决问题吗?
我正在显示一个文件列表; 即我的Java应用程序(Eclipse RCP)中的xls,doc,pdf,odt等.当用户单击该文件时,我想启动相应的(根据操作系统认为的)本机应用程序,就像在Windows资源管理器或Finder中一样.
当我在这里时:最好还显示Finder或Explorer用于不同文件类型的相同图标.
是否有一个库或Eclipse插件?
我有一个打开文件的java应用程序.这在Windows上运行得很好,但在mac上却不行.
这里的问题是我使用Windows配置打开它.代码是:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
现在我的问题是在mac中打开它的代码是什么?或者还有另一种方法可以打开可以运行多平台的PDF吗?
编辑:
我创建了如下文件:
File folder = new File("./files");
File[] listOfFiles = folder.listFiles();
Run Code Online (Sandbox Code Playgroud)
在循环中我将它们添加到一个数组:
fileArray.add(listOfFiles[i]);
如果我尝试使用Desktop.getDesktop().open(文件)从该数组中打开一个文件,它说它找不到该文件(因为我使用'./files'作为文件夹,路径搞砸了)
java ×3
eclipse-rcp ×1
explorer ×1
file ×1
file-manager ×1
finder ×1
jfilechooser ×1
pdf ×1
swing ×1