I have a Swing JFrame. If I create a new JFrame in a new thread during the program execution where will be the EDT ? In the current thread of the last JFrame window or in t
The EDT - the event dispatch thread - is separate from any concrete GUI component, such as a JFrame.
Generally you should create all GUI components on the EDT, but that does not mean they own the EDT, nor does the EDT own the components.
To create two JFrames, both on the EDT, you can do the following:
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame1 = new JFrame("Frame 1");
frame1.getContentPane().add(new JLabel("Hello in frame 1"));
frame1.pack();
frame1.setLocation(100, 100);
frame1.setVisible(true);
}
});
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame2 = new JFrame("Frame 2");
frame2.getContentPane().add(new JLabel("Hello in frame 2"));
frame2.pack();
frame2.setLocation(200, 200);
frame2.setVisible(true);
}
});
}