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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:22:25+00:00 2026-05-27T19:22:25+00:00

I have a tabbed view in my program and under each tab I have

  • 0

I have a tabbed view in my program and under each tab I have several panels which I rotate between with buttons. I’ve decided to implement a CardLayout for each one of these tabs, and given that I have about 7 tabs I decided to write a class to make things a bit neater. The class is called PanelSystem and it takes in JPanels which have already been created and adds them to a CardLayout. I will also implement a switchPanel method to move between panels. So far I have:

public class PanelSystem {

JPanel cards;
CardLayout cl;

public PanelSystem(JPanel...panels) {
    // Create Panel with card layout
    cards = new JPanel(new CardLayout());

    // Add all the panels to the card system
    for (JPanel p : panels) cards.add(p);

    // Gains access to the card layout?
    cl = (CardLayout)(cards.getLayout());

    // Show starting card
    cl.show(cards, *UNIQUE IDENTIFIER*);
}
}

Since there are different numbers of JPanels for each tab I had to implement the JPanels…panels line. I’m not sure if this works correctly yet, but the problem comes at the end of the constructor where I’m trying to show the first card since it doesn’t have a unique identifier because of the way I added them. Any thoughts on how I could fix this?? Thanks in advance guys!

  • 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-27T19:22:25+00:00Added an answer on May 27, 2026 at 7:22 pm

    You can access the varargs as if it were an array (which it is, anyway). How about if you loop through it with a classical for loop

    for (int i = 0; i < panels.length; i++) {
        cards.add(panels[i], Integer.toString(i));
    }
    

    then at the end

    cl.show(cards, "0");
    

    Edit: I’m rusty on Swing layouts, can’t remember exactly whether you need your identifier to be a String or just any Object, but you should be able to figure it out from here.

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

Sidebar

Related Questions

My application is a Tabbed Application, and it have several controllers under the tabBarController.
I have a tabbed view with one Activity per tab, and when I switch
What i have is a tabbed page with 12 tabs (every tab is a
I have a swing gui with a tabbed pane in the north. Several key
I have an app with 2 tabbed view, I wish to execute some code
I have a storyboard setup as a Tabbed Application with first view controller containing
I have a tabbed application with navigation controllers in tabs and view controller in
I have a tabbed application with navigation controllers in tabs and view controller in
I have created a tabbed view with four tabs and attached four listviews to
I'm making a tabbed view application and using CloudMade's API. I have a working

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.