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