aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to exit JFrame2 when going back to JFrame1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to exit JFrame2 when going back to JFrame1" Watch "How to exit JFrame2 when going back to JFrame1" New topic
Author

How to exit JFrame2 when going back to JFrame1

Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Hi!

Newbie here.

I have a small program that opens up JFrame1. Clicking on a button creates a new JFrame (JFrame2) and hides JFrame1. I have a button on JFrame2 which says "BACK". I want this button to "kill" JFrame2 and take me back to JFrame1. How do I do that? Unload JFrame2 or whatever it might be called?

Regards
Peter
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
sounds like you would be better off using a modal JDialog instead of frame2.
no need then to hide frame1, it is not accessible until the modal dialog closes
Peter Hammar
Ranch Hand

Joined: Mar 01, 2010
Posts: 34
Hi!

No, thats not what Im looking for. I would like to have a couple of buttons on my JFrame2.

Regards
Peter
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

I think a CardLayout is what you want. Instead of two different frames you have one frame. Inside this frame you have a JPanel with the contents of both frames. The first button shows the next card, the second button shows the previous card.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Peter Hammar wrote:Hi!

No, thats not what Im looking for. I would like to have a couple of buttons on my JFrame2.

Regards
Peter


Agree that CardLayout could work best, but also you may have a significant misconception about what a JDialog is and can do. Do you know for instance that JDialogs can hold GUIs that are every bit as complex as JFrames, "couple of buttons" and all?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to exit JFrame2 when going back to JFrame1