This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to exit JFrame2 when going back to JFrame1

 
Peter Hammar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic