I’m developing an application that features multiple Swing GUIs. The main GUI has a button that, once pressed, calls the other GUI. The problem is that both of the windows hang once that button is pressed and the new GUI appears.
I’ve been looking into SwingUtilities.invokeLater but I can’t use it for creating the first GUI as I’m passing it a reference to an object that I don’t want it to be ‘final’ as the compiler demands.
The first GUI is created with:
MainUI gui = new MainUI(player);
gui.setVisible(true);
The second one is created with:
private void challengeBtnActionPerformed(java.awt.event.ActionEvent evt) {
if (board.isVisible()) {
board.dispose();
resetComponents();
} else {
MainUI gui = new MainUI(player);
gui.setVisible(true);
}
}
Can you help me, please?
Once again: you should not interact with Swing components from any thread except the EDT.
You should invoke your
MainUIin the following way:You can redesign your app to make it possible to invoke your
MainUIin such a way.UPDATE:
The following code should work.