import java.awt.Window;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

public class Playground {

	public static void main(String... args) {
		SwingUtilities.invokeLater(() -> {
			JOptionPane.showMessageDialog(null, "This is a test, do not panic.");

			int result = new JFileChooser().showOpenDialog(null);
			System.out.println(result);

// ...hangs forever, unless:

// This fixes it by manually disposing of the problematic frame:
// JOptionPane.getRootFrame().dispose();

// This is a cleaner version of the workaround:
			
			//for (Window window : Window.getOwnerlessWindows()) { window.dispose(); }
			 
		});
	}

}