SWT的选择文件和文件夹的函数

时间:2023-03-08 17:20:46

org.eclipse.swt.widgets.DirectoryDialog//选择目录
org.eclipse.swt.widgets.FileDialog//SWT.OPEN打开文件 SWT.SAVE保存文件

选择文件:

FileDialog fileselect=new FileDialog(shell);
fileselect.setFilterNames(new String[]{"*.*","所有文件"});
fileselect.setFilterExtensions(new String[]{"*.*","*.*"});
String url="";
url=fileselect.open();
System.out.println(url);

选择文件夹:

DirectoryDialog  fileselect = new DirectoryDialog(shell);
fileselect.setFilterNames(new String[]{"*.*","所有文件"});
fileselect.setFilterExtensions(new String[]{"*.*","*.*"});
String url="";
url=fileselect.open();
System.out.println(url);