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 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
  • 1 View
  • 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 looking at some code and I'm curious whether this is good practice. class
I am curious whether it is possible to determine the maximum size that an
I heard that .NET 4 has a new caching API. Okay, so the good
I'm just curious whether there is a gui framework that alloys you to use
I am new to Perl and am curious whether @{$list_ref} and @$list_ref are perfectly
I am just curious whether I can include an object into function prototype chain.
Curious whether folks have setup 2 way transactional replication on the tables ASP.NET uses
When a popover shows, I'm curious whether it's possible to set the underlying settings
I was curious as to whether or not there exists a jQuery-style interface/library for
I am curious to know whether anyone out there have tried mixing node.js headless

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.