Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: adding or removing panels to panels

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default adding or removing panels to panels

    Hi everyone, I need help with JPanel

    I have a panel named "contentPanel" inside of a Main Frame and I am inserting to that panel another JPanel "MyPanel" from another class with add.()

    contentPanel.setLayout(new BorderLayout(5, 5));
    contentPanel.add(MyPanel, BorderLayout.CENTER);
    What I want is to hide that new panel inserted (MyPanel) and insert or show another on top of it, that means I have contentPanel that has MyPanel but in an exact moment, I want it to change to OtherPanel for example (OtherPanel is a panel from another class).

    If I do add() with the new panel, it appears in top of MyPanel and all the components from both panels show up, and dont work.

    Thanks and hope you understand my english.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: adding or removing panels to panels

    Can't u just set it to trigger setVisible(true) or false?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: adding or removing panels to panels

    Quote Originally Posted by macko View Post
    Can't u just set it to trigger setVisible(true) or false?
    Not necessarily, since he's adding the second JPanel to the first. He wants the first one to go away, but setting it to invisible would also cause the second one to become invisible. CardLayout is the solution to this.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Not Removing Panels?
    By Pantheon8 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 17th, 2011, 07:54 PM
  2. JTabbedPane with two Panels in the same tab?
    By cadarn in forum AWT / Java Swing
    Replies: 1
    Last Post: August 3rd, 2011, 10:48 AM
  3. Help with Layouts and Panels
    By Zookey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 29th, 2011, 06:48 PM
  4. Removing the middle cell
    By Shyamz1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 7th, 2010, 01:35 PM
  5. Adding panels to a central panel.
    By Johannes in forum AWT / Java Swing
    Replies: 3
    Last Post: July 4th, 2010, 05:31 PM