My swing application has a main window in which there are several buttons. This JFrame runs in EDT ...
EventQueue.invokeLater(new Runnable() { public void run() { JFrame server = new JFrame(); server.setVisible(true); server.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //Do other stuff here } });
Each button can launch a separate JFrame.
I'm not sure if I need to start a new EDT thread to start each of these new windows? Thank.
Usually, when you are in a button handler (for example, an actionlistener), this causes an EDT. You can verify this using SwingUtilities.isEventDispatchThread
No problem - every action handler runs on EDT. Therefore, if you open a new one JFramefrom such a place, there will be no problems.
EDT
JFrame
- (, ) , , , , EDT. SwingWorker invokeLater.
SwingWorker
invokeLater
, , .. EventDispathThread
yes InitialThread
, JFrame , EDT ,
JFrame#pack() // finalize & calculate used LayoutManager
JFrame#setVisible(true) // display Container on the screen
Each button can launch a separate JFrame. , CardLayout , betweens, , JFrame JDialog