Java – SWT FileDialog: select a directory instead of a file

Can you use SWT FileDialog to select a folder instead of a file?

Solution

You can use directorydialog Here are 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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
***
下一篇>>