File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to exit JFrame2 when going back to JFrame1

 
Peter Hammar
Ranch Hand
Posts: 34
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • 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
  • 0
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic