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

  • Home
  • SEARCH
  • 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 994511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:35:12+00:00 2026-05-16T06:35:12+00:00

I am curious whether it is good practice to make a new main JPanel

  • 0
  1. I am curious whether it is good practice to make a new main JPanel object every time a user wishes to return to that JPanel from a subsequent JPanel?

  2. FYI, my Swing application has a JFrame whose first object is a mainJPanel with three JButtons (one of them is a Review button).

  3. Let’s say the user pushes the Review button. The program calls removeall() on the JFrame’s content pane and creates a new reviewJpanel object which has a JTable and a JButton (let’s call it Finish Review).

  4. Let’s say the user finishes reviewing and pushes the Finish Review button. The program’s intention is to return to the mainJPanel screen, so it creates a new mainJPanel object exactly the same as in para 2 above.

  5. I am wondering if is it redundant to make a new mainJPanel object each time? But if I were to keep the mainJPanel somehow, how could I remove the reviewJPanel from the JFrame when the user pushes the Finish Review button?

  6. I hope these questions are useful for other users new to Swing. I have a couple of Swing books and regrettably they seem to overlook the question of handling “main” JPanels and multiple subsequent JPanels and switching back and forth.

  • 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-05-16T06:35:13+00:00Added an answer on May 16, 2026 at 6:35 am

    If you only have one panel at a time, just change panels with setContentPane. When you first create your frame, do frame.setContentPane(mainJPanel);. Then, when the user clicks a button, do frame.setContentPane(otherPanel);. The mainJPanel will be replaced by the new panel, and when the user is done, you can use frame.setContentPane(mainJPanel); again to put the main panel back. You don’t have to waste resources recreating the panel, and it’s faster and more effecient than using removeAll and adding the new panel.

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

Sidebar

Related Questions

I'm curious whether many of us who do design or take design decisions have
I'm curious to know whether the PDFKit framework is available for use within the
Although I'm doubtful, I'm curious as to whether it's possible to extract primitive-type template
Is it considered good or bad practice to use MySQL's password function to hash
I'm looking to determine whether a string value from a user input (UITextField) is
curious if anyone might have some insight in how I would do the following
Curious to know how people set up their personal and/or work development environment, in
Curious to get people's thoughts. I conduct frequent interviews, and have had enough in
Curious as to 99.95% uptime REALLY means; Is it really going to go down
I curious to how different people solve integration of systems. I have a feeling

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.