Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:42:12+00:00 2026-06-07T04:42:12+00:00

How to make an added JPanel visible inside a parent JPanel ? I am

  • 0

How to make an added JPanel visible inside a parent JPanel?

I am using Netbeans for designing my UI.

I have a MainFrame.java, which contains two panels; namely headerPanel and bodyPanel.

In headerPanel I have put three buttons,let it be button1, button2 and button3.

Also I have created three separate files extending JPanel, name it panel1, panel2 and panel3.

Then I added all my three panels inside bodypanel in MainFrame.java in constructor.

bodyPanel.add(panel1);
bodyPanel.add(panel2);
bodyPanel.add(panel3);

I want that on clicking the respective buttons only respective panels should appear in the bodypanel in mainframe, i.e. if I click button1 then panel1 should be displayed.

I have already tried the following code in button1 mouse listener method:

bodyPanel.validate();
bodyPanel.getComponent(0).setVisible(true);

But panel1 does not appear. I did it cause added components in a panel are allotted index. So first I tried to get the components and then make it visible. It did not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:42:15+00:00Added an answer on June 7, 2026 at 4:42 am

    Use a CardLayout, as shown here.

    Game view High Scores view

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JPanel parent with 3 JPanel children inside. They all currently make
I have added a nice little bit of jquery which make images black and
I have a subclass of JFrame(it contains JButton, Title and Jpanel) and i added
I would like to make a layout using Java Swing which looks like the
Im using swing in java to make a quiz for my coursework. I have
I have a main JPanel which implements Scrollable and uses a BorderLayout. It contains
I have a static Web project added to an Apache server. Whenever I make
I'm trying to make a custom infowindow. Version = 2. I have added my
I have a JPanel that has several (25) JLabel s on it, using a
I have created a JDialog which contains a JComboBox and a panel underneath which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.