user3503758 user3503758 - 2 years ago 379
Java Question

How to go back to previous frame that was invisible

I am very new to Java Swing and I am working on a login frame with swing that works like this.

After I login successfully in a frame, another new frame is opened while the login frame goes to invisible.

What I am trying to do is that when i close the another frame (after login frame) I want the previous login frame to show again from invisible to visible. please let me know how to do this..:)

Answer Source

Suppose your previous frame is myPreviousFrame

just write myPreviousFrame.setVisible(true); when you want to make visible.



Note: if you write code System.exit(0) it will close (terminate) your application. When your application goes terminate you can not make login frame as visible. You need to restart your application. So you need to write dispose().


I suppose you have a method exitForm() which invokes when you click the Close (X).


private void exitForm(java.awt.event.WindowEvent evt) {                          
     //System.exit(0); which was used 
     // to fullfill your requirement you need to write below code
     this.dispose();// here [this] keyword means your current frame
     //OR simply you can use this.setVisible(false); instead of this.dispose();
     myPreviousFrame.setVisible(true); // this will displays your login frame
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download