1

I have a swing app that I would like to use Windows7/Vista style FileDialogs and have found a reasonable solution using SWT in conjunction with swing: Does Swing support Windows 7-style file choosers?

However, now I'm trying to get this same dialog to accept only directories (the "Select Folder" button instead of the "Open" button).

I do not want to use the typical DirectoryDialog:

enter image description here



I want to use the Dialog with favorites on the left, address bar on the top, and the ability to select folders:

enter image description here

Anyone know how to accomplish this?

Replies are greatly appreciated.

Community
  • 1
  • 1
MGreenfield
  • 355
  • 1
  • 13
  • 2
    The simple answer is: You can't. That's what the `DirectoryDialog` is for. There currently is no way to get the "Windows 7 style" dialog for choosing directories with SWT, sorry. – Baz Jul 19 '13 at 19:20
  • What about with any other framework in Java? Is it just that Java can't use that type of dialog that only selects folders? Seems strange. – MGreenfield Jul 19 '13 at 23:48
  • No idea, I don't use other frameworks. – Baz Jul 20 '13 at 08:46

2 Answers2

0

Baz already said it: It is not possible to get this dialog using SWT. To answer your question about other frameworks: I believe there are plenty, for example you could use Jide. You do not get the dialog you want, but at least you get an enhanced version (FolderChooser) with few advantages:

  • Convenience-Buttons (Desktop, My Documents, ...)
  • Delete/Create new directory
  • Address bar

And the best of all this: You get it for free, cause it's in the "Common Layer". You can try the FolderChooser by launching the Demo-WebStart-Project.

Bluddymarri
  • 313
  • 1
  • 3
  • 12
-1

It's kind of a hack:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Demo{

    public static void main(String [] args) {
        Display display = new Display();
        Shell shell = new Shell(display);  
        FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
        dialog.setFilterPath("c:\\");

        //The extension doen't excist!
        dialog.setFilterExtensions(new String[] {"xyz"});
        //You can also use " ";

        dialog.open();
        shell.close();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}

I tryed it out and I think, it works well!