我需要知道如何在Java中获取“浏览文件夹”对话框。我知道SWT,但我需要在Swing中实现。是否有解决方案?
[当我们启动eclipse时,它会要求选择工作区。此时我们可以看到浏览文件夹对话框] 提前感谢。
我需要知道如何在Java中获取“浏览文件夹”对话框。我知道SWT,但我需要在Swing中实现。是否有解决方案?
[当我们启动eclipse时,它会要求选择工作区。此时我们可以看到浏览文件夹对话框] 提前感谢。
如果您添加以下命令,可以强制JFileChooser仅选择文件夹。
_fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY);
在Bibhaw发布的片段中。JFileChooser j = new JFileChooser();
j.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Integer opt = j.showSaveDialog(this);
预先嚼碎的代码:
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new java.io.File(".")); // start at application current directory
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File yourFolder = fc.getSelectedFile();
}
JFileChooser chooser = new JFileChooser("C:\example");
详情请查看:
http://leepoint.net/notes-java/GUI/containers/20dialogs/30filechooser.html
http://download.oracle.com/javase/tutorial/uiswing/components/filechooser.html