0

I have a method that displays a DirectoryDialog. But I call it within a JFrame. When I call the method below, it opens up a "Shell", which is basically like another window, and then pops up the DirectoryDialog.

How do I get rid of this JFrame-like shell. I already have a JFrame, and I want the JFrame to be the parent, not some random shell that I need to create additionally.

In other words, I need to get rid of the additional window that pops up when I call this method.

public File[] fileDialog(boolean folder){
    if(folder){
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.open();

        DirectoryDialog dialog = new DirectoryDialog(shell);
        dialog.setFilterPath("C:\\"); // Windows specific
        String file = dialog.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
        if(file == null)
            return new File[0];
        else if(file.length() == 0)
            return new File[1];
        else{
            File[] files = new File[1];
            files[0] = new File(file);
            return files;
        }
    }
}
ThePrince
  • 818
  • 2
  • 12
  • 26
  • 1
    For better help sooner, post a [Minimal Complete Tested and Readable Example](http://stackoverflow.com/help/mcve) (MCTRE). – Andrew Thompson Feb 03 '14 at 22:43
  • 1
    BTW - DYM the [SWT `Shell`](http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fwidgets%2FShell.html)? – Andrew Thompson Feb 03 '14 at 22:45
  • 1
    Perhaps you would be better off with a `JFileChooser` using the native PLAF (which is more like, but still not entirely like, the standard Windows file chooser), or a custom Swing component based on the [File Browser GUI](http://codereview.stackexchange.com/questions/4446/file-browser-gui). – Andrew Thompson Feb 04 '14 at 00:37

0 Answers0