• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to exit JFrame2 when going back to JFrame1

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22788
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic