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 6 of 6

Thread: Calling a JPanel into another Jpanel in a JFrame

  1. #1
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Calling a JPanel into another Jpanel in a JFrame

    Please am trying to understand how to insert a standalone JPanel (viewPanel) that doesn't extend a JFrame into another JPanel (mainPanel) that is in a JFrame. Would have posted the code, but they codes are very very much. I was thinking i could use a ContainerListener on the mainPanel, but i don't know if that is right! please help.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Calling a JPanel into another Jpanel in a JFrame

    Of course a JPanel doesn't extend a JFrame - that goes without saying and that you did say it is a bit confusing.

    Other than that, I was with you until you mentioned the listener. I can't fathom why a listener of any kind would be required, so I'm thinking I don't understand your question. Before you rephrase or explain further, review layouts. The CardLayout may be useful here.

    As I reread your statement, the more confused I become. I'm not really sure what you're asking.

  3. #3
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Calling a JPanel into another Jpanel in a JFrame

    Ok lets say you have a JFrame with a mainPanel that is initially empty (that is; it has no components by default) and then you want to add a component to it - like another JPanel - by clicking a button, how can you achieve that? It's possible to add a JPanel to a JPanel, Yes?

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Calling a JPanel into another Jpanel in a JFrame

    Yes, that's possible. Show what you've tried.

  5. #5
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: Calling a JPanel into another Jpanel in a JFrame

    You should just be able to call the add() method to add the second JPanel to the first one.

  6. The Following User Says Thank You to GoodbyeWorld For This Useful Post:

    aknessy (October 17th, 2013)

  7. #6
    Member
    Join Date
    Apr 2011
    Location
    Niperia
    Posts
    30
    My Mood
    Amazed
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Calling a JPanel into another Jpanel in a JFrame

    Thanks for your suggestions guys, but i found an easier solution in JTabbedPane. I'll just stick with that! thanks though.

Similar Threads

  1. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  2. [SOLVED] JPanel not showing in JFrame
    By Tjstretch in forum AWT / Java Swing
    Replies: 2
    Last Post: October 31st, 2011, 12:27 AM
  3. [SOLVED] What is not right here? adding JPanel in JFrame
    By Asido in forum AWT / Java Swing
    Replies: 2
    Last Post: August 23rd, 2010, 08:16 AM
  4. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM
  5. need help with ActionListener,JPanel,JFrame
    By amahara in forum AWT / Java Swing
    Replies: 5
    Last Post: February 3rd, 2010, 01:40 PM