Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWT FileDialog: Selecting directories instead of files

Tags:

java

swt

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

like image 931
becks Avatar asked Aug 27 '12 11:08

becks


1 Answers

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.

like image 97
Baz Avatar answered Sep 22 '22 07:09

Baz