Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: How do i open JFrame2 inside of JFrame1 by pressing a button?

  1. #1
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default How do i open JFrame2 inside of JFrame1 by pressing a button?

    Hello, new to this forum, hopefully some ppl will help me with this..I have main JFrame1, and it has some buttons on it. I know how to make it so JFrame1 would close and only JFrame2 would be visible, once i press a button. Can i open JFrame2 in the same window (JFrame1) by pressing a button? What tutorial do i need to search for this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i open JFrame2 inside of JFrame1 by pressing a button?

    Often what you want to do is to swap views (JPanels holding a GUI on it) in a single stable window rather than swap windows. This can be best accomplished via CardLayout.

    The CardLayout tutorial is here: How to Use CardLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
    The Swing tutorials are here: Lesson: Using Swing Components (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    And the Java tutorials are here: The Really Big Index

  3. #3
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: How do i open JFrame2 inside of JFrame1 by pressing a button?

    thank you, ill look into it

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: How do i open JFrame2 inside of JFrame1 by pressing a button?

    Good luck, and let us know how it goes!

  5. #5
    iNko is offline Member
    Join Date
    Dec 2012
    Posts
    55
    Rep Power
    0

    Default Re: How do i open JFrame2 inside of JFrame1 by pressing a button?

    Tried for couple of hours, no success :(
    I think the easiest method for me will be just to make multiple frames, pressing a button will open a new frame and close the old one.. is this a bad idea? cardlayout seems just too complex for me..

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: How do i open JFrame2 inside of JFrame1 by pressing a button?

    That is a bad idea, and CardLayout isn't all that complex. Just go through the exercises in the tutorial -- don't just read them, type the code and try it out for yourself.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. pressing a button making a instance in another class
    By SpicyElectricity in forum New To Java
    Replies: 3
    Last Post: 02-18-2012, 10:48 PM
  2. Draw shapes by pressing a button
    By SWEngineer in forum AWT / Swing
    Replies: 16
    Last Post: 05-14-2010, 05:26 AM
  3. Replies: 2
    Last Post: 04-12-2009, 10:39 AM
  4. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  5. Replies: 5
    Last Post: 01-17-2008, 09:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •