FileChooser and Slow Operation in EDT

Hi, I have a JButton that triggers a file selection by invoking a com.intellij.openapi.fileChooser.FileChooser.
Basically, it looks like

myButton.addActionListener(al -> {
    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(...);
    VirtualFile virtualFile = FileChooser.chooseFile(fileChooserDescriptor, null, null); // <- error here
    ...
});

This triggers a Slow operations are prohibited on EDT exception.

If I move FileChooser.chooseFile outside from the EDT, it says I need to run in EDT…

A workaround is to replace com.intellij.openapi.fileChooser.FileChooser by a good old javax.swing.JFileChooser, but its UI is ugly.

Do you know how to integrate a FileChooser? Thanks.

1 Like