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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:26:08+00:00 2026-06-08T18:26:08+00:00

I’ve reccently run into issues with indexing my tabs and though I’d give it

  • 0

I’ve reccently run into issues with indexing my tabs and though I’d give it some concrete ordering by using the setComponentAt method. Here’s my code:

public ContainerPane() {
    this.setLayout(new BorderLayout());
    myPlayerManagerPane = new PlayerManagerPane();
    myGameManagerPane = new GameManagerPane();
    myCharacterManagerPane = new CharacterManagerPane();

    myPaneTab = new JTabbedPane(JTabbedPane.TOP);
    myPaneTab.addTab("Character",myCharacterManagerPane);
    myPaneTab.addTab("Player",myPlayerManagerPane);
    myPaneTab.addTab("Games",myGameManagerPane);
    System.out.println(myPaneTab.getTabCount());
    //myPaneTab.setEnabledAt(1, false);
    //myPaneTab.setEnabledAt(2, false);
    myPaneTab.setComponentAt(0, myPlayerManagerPane);
    myPaneTab.setMnemonicAt(0, KeyEvent.VK_1);
    myPaneTab.setComponentAt(1, myCharacterManagerPane);
    myPaneTab.setMnemonicAt(1, KeyEvent.VK_2);
    myPaneTab.setComponentAt(2, myGameManagerPane);<---outOfBoundsException
    myPaneTab.setMnemonicAt(2, KeyEvent.VK_3);
    add(myPaneTab);
}

So for the count I have, 3 tabs (according to me, and getTabCount()), and I am counting from 0 (correct?). I’m setting the last index the last component that I have. But I still have this printing to screen:

3 <---from tabCount
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2

Where am I tripping up, is there an easier way to order my panes?

Edit: Commenting out the setComponent methods, and putting in a for loop I get this output:

There are 3 tabs!
Tab at 0 is Character
Tab at 1 is Player
Tab at 2 is Games

And uncommmenting one pair of methods at a time, I get only 2, of the one I’ve not overwritten, and one of the ones I’ve now set.

Is setComponentAt removing duplicates? Should I ever have fewer than 3 tabs with my set up? Does JTabbedPanel have odd behaviour for duplicate panes?

  • 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-08T18:26:09+00:00Added an answer on June 8, 2026 at 6:26 pm

    I’m not sure how or why setComponentAt wasn’t working, though it could be the fact that tabs use a Vector and I’ve heard they are bad.

    If you want to have a fixed order of adding, just use insertTab Like so:

    myPaneTab.insertTab("Games",null, myGameManagerPane,"CharacterManagerPane",2);
    

    Where null is for the icon, and doesn’t accept it as an empty argument.

    This way you know in your source code the index of the tab. The only issue with this is that you can’t add a new tab at an index past the current tabCount (which you can find via getTabCount), i.e. you can’t count 1,3,4 with your tabs!

    I’m sure you could write a new JTabb Class, and overload the insertTab method to do something more helpful but it might obsfuscate where the tab is (I.e this way you could tell it put the tab at index 2 and it goes into index 1.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words

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.