I use the recommended code to start my interactive program, which uses Swing. :
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(
new Runnable() {
public void run() {
createAndShowGUI();
} } ) };
It creates a JFrame, call it "Foo", and ends when the user closes that window (by using the OS' Close- Window X icon or another OS way to close the app)
I want to display another window, "Bar", get user input, close that window with my own Swing calls, and then display the "Foo" window.
I could reuse the same JFrame for Foo and Bar, and just clear it out in-between. But I prefer to make each of them more independent in their design. So, an ActionListener in Foo would need to close Foo's frame, and call the code that displays Bar.
Do I need to use InvokeLater() to call the code that displays Bar? To get more design independence, should my main() be starting and synchronizing two threads?
you would use
pack()
andsetVisible(true)
wrapped intoinvokeLater
in all cases forfor new
Top-Level Container
- alywaysfor container created but never dispayed - always
for container once visible, then hidden and again visible on the screen - always
doesn't matter if is invoked from Swing Listener (by default on EDT) or not
to my point 3rd. to avoiding any unwanted
Graphics
lacks in the case that you reusedTop-Level Container
(is specifics, very short moment, but could be visible, but not, never annoying)old value is visible, then immediatelly refreshed to current
old
JComponent
is visible, then immediatelly refreshed with currentJComponents
relayout
/pack()
, the same issue as a.m.invokeLater
to delay (in most casses with success) this event to the end ofEDT
see my view translated to the code demonstration about