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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:31:11+00:00 2026-05-26T00:31:11+00:00

I can only see the JPanel added at last. Previous ones seem to be

  • 0

I can only see the JPanel added at last. Previous ones seem to be replaced by the last one. Why is this? Here’s my code. Thanks in advance.

...
class GUIController {



    BaseFrame bf = new BaseFrame(); //is a JFrame




    public void showFrame(final String frameName, final JPanel... panels){

        EventQueue.invokeLater(new Runnable() {
                public void run() {
                     try {
                            Class c;
                            Constructor ctr;
                            c = Class.forName("com.mytunes.client.views.frames." + frameName + "Frame");

                            ctr = c.getConstructor();

                            bf.removeAll();

                            bf = (BaseFrame) ctr.newInstance(); // no issue with getting the JFrame dynamically created!


                            for(JPanel panel:panels){

                                switch(i){
                                    case 1: bf.getContentPane().add(panel,BorderLayout.PAGE_START);

                                        break;

                                         case 2:
                                        bf.getContentPane().add(panel,BorderLayout.CENTER);
                                       break;

                                         case 3:
                                        bf.getContentPane().add(panel,BorderLayout.PAGE_END);
                                        break;

                                }

                            }
                            bf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                            bf.pack();
                            bf.setVisible(true);

                        } catch (InstantiationException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalAccessException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalArgumentException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (InvocationTargetException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (NoSuchMethodException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SecurityException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (ClassNotFoundException ex) {
                            Logger.getLogger(GUIController.class.getName()).log(Level.SEVERE, null, ex);
                        }
           }

       });



    }


    public void showEnterCard(String frame){

        JPanel p1 = new JPanel();
        JPanel p2 = new JPanel();
        JPanel p3 = new JPanel();

        showFrame(frame, p1,p2, p3);
    }

}

class Main{
    public static void main(String args[]){
        GUIController c = new GUIController();

        c.showEnterCard("FirstFrame");
    }
}

EDIT: (solution)

Loop changed as follows:

for(int i = 1; i <= panels.length; i++){
     switch(i){
        case 1: 
              bf.getContentPane().add(panels[0],BorderLayout.PAGE_START);
        break;
         ...
     }
}
  • 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-26T00:31:12+00:00Added an answer on May 26, 2026 at 12:31 am

    you never change i, it is always one, so case 1: in the switch is always true, and the JPanel is always added to the same place.

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

Sidebar

Related Questions

I can only see inline CSS and JS while viewing the source code of
Any sample code to do so ? I can only see example for passing
Here is my code: //this is a JPanel, the gray panel behind the A4
When I create new Listcell( a) I can only see output as a instead
I'm trying to secure an application so that users can only see objects which
When I execute a sql statement like Select ..., I can only see ...100%
I'm trying to show thumbnail images in Django admin, but I can only see
Intellisense popup in VS2010 is driving me crazy. I can only see 9 items
Is DataContract attribute is deprecated in ASP.NET 4.0 WCF ? I can see only
How can i check to see if a string only contains spaces?

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.