If JFrame always runs in EDT

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.

+3
source share
3 answers

Usually, when you are in a button handler (for example, an actionlistener), this causes an EDT. You can verify this using SwingUtilities.isEventDispatchThread

+4
source

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. SwingWorker invokeLater.

+3

  • , 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

+2

All Articles