I have a Swing UI with a certain number of buttons. One button invokes a separate swing class, and a new window opens with new buttons and other functions. Now, when I close this window, the original window also closes. I think this is because both classes are impedmented
javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { //some code } }
Now how to overcome this? A sample code or link will be very helpful. Thanks
It's hard to guess without seeing the code. Perhaps your JFrameinstalled setDefaultCloseOperationto close the application when the window is closed (perhaps EXIT_ON_CLOSE). See the java doc for more information on this.
JFrame
setDefaultCloseOperation
EXIT_ON_CLOSE
From java doc :
EXIT_ON_CLOSE ( JFrame): , System exit. .
System exit
, . . ( ).
SwingUtilities.invokeLater . - run, GUI .
SwingUtilities.invokeLater
run
EXIT_ON_CLOSE, , System.exit().
System.exit()
, EXIT_ON_CLOSE , . . Javadoc.
, setDefaultCloseOperation .
, Swing, EDT Thread Dispatch Thread, SwingUtilities.invokeLater, , , , , , EDT. , , JButton ActionListener, SwingUtilities.invokeLater, actionPerformed EDT.
, JDialog - , , JFrame. JFrame , , .
, , JDialogs , , JFrame.
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) JFrame.
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) , JFrame , EXIT_ON_CLOSE , JFrame .