user3503758 user3503758 - 1 year ago 271
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..:)


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