SWT FileDialog: Selecting directories instead of files

后端 未结 1 571
面向向阳花
面向向阳花 2020-12-06 11:02

Can I use the SWT FileDialog to select folders instead of files?

相关标签:
1条回答
  • 2020-12-06 11:40

    You could use the DirectoryDialog instead. Here is some sample code:

    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();
    }
    

    Here is a slightly larger example.

    0 讨论(0)
提交回复
热议问题