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 7962927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:28:54+00:00 2026-06-04T05:28:54+00:00

I have a main JPanel target in MainFraim and another currentView JPanel, which is

  • 0

I have a main JPanel target in MainFraim and another currentView JPanel, which is added to the target panel. target panel contains buttons with listeners. These listeners are then supposed the change the content of the curretView panel, as demonstrated below:

private JPanel currentPanel;

public void setView(String type) {

    if (type.equals("overall")) {
        this.currentPanel = getOverallView();
        frame.setTitle("BookingCalendar - Overall View");
        frame.validate();
    } else if (type.equals("guest")) {
        this.currentPanel = getGuestView();
        frame.setTitle("BookingCalendar - Room View");
        frame.validate();
    } else if (type.equals("room")) {
        currentPanel.removeAll();
        this.currentPanel = getRoomView();
        frame.setTitle("BookingCalendar - Guest View");
        frame.validate();
    }
}

Every method I call returns new JPanel each time it is called:

JPanel currentPanel = new JPanel(new MigLayout("","20 [grow, fill] 10 [grow, fill] 20", "20 [] 10 [] 20"))

The problem is, whenever I call these methods, the panel won’t change. It always stays the same (by default: getOverallView() )

I’ve tried with invalidate, validate, repaint on both frame, as well as the panel, but no changes occur. Could someone please elaborate more as to what I need to do in order to completely change the content of the panel currentView

  • 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-04T05:28:55+00:00Added an answer on June 4, 2026 at 5:28 am

    You shouldn’t be creating a new JPanel() every time. Instead create one for each type of view, and use a CardLayout to switch between them. CardLayout lets you have JPanels that get switched out like cards.

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

Sidebar

Related Questions

I have a main JPanel which implements Scrollable and uses a BorderLayout. It contains
In the example below I have a JPanel with BoxLayout which contains another JPanel
I have 3 panels. One is the main panel which holds 2 smaller panels.
I have a JPanel which is set to BorderLayout . I have added 2
I have a JPanel subclass on which I add buttons, labels, tables, etc. To
I have a frame on which i have created a main panel. On that
I have a JFrame and a Jpanel over that in which various buttons are
I have a JPanel added to a JViewport , and the panel has several
I have a program in which a JPanel is added to a JFrame: public
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has

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.