java SWT FileDialog:选择目录而不是文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12140884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:46:04 来源:igfitidea点击:
SWT FileDialog: Selecting directories instead of files
提问by becks
Can I use the SWT FileDialog
to select folders instead of files?
我可以使用 SWTFileDialog
来选择文件夹而不是文件吗?
回答by Baz
You could use the DirectoryDialog
instead. Hereis some sample code:
你可以用DirectoryDialog
代替。下面是一些示例代码:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.open();
DirectoryDialog dialog = new DirectoryDialog(shell);
dialog.setFilterPath("c:\"); // Windows specific
System.out.println("RESULT=" + dialog.open());
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Hereis a slightly larger example.
这是一个稍大的例子。