Close FileChooser window immediately after OK/Cancel


Hi, I am using FileChooser to open and select file in native dialog box. After I’ve selected the file and OK I’d like the box to close immediately when browseForFileOpen() returns. At the moment it seems the closure is handled somewhere in the system many seconds later.

Whats the best way to close this immediately?


Without knowing your code, I assume that you are doing something time consuming in the same method, that modally shows the FileChooser. The FileChooser is closed, when it goes out of scope.
You can probably simply call chooser.setVisible (false); right after it returns.
But it would be better to offload the loading to a background thread, since you observed already, that it made your app unresponsive.