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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:43:17+00:00 2026-06-04T19:43:17+00:00

Im basicly trying to add in a bunch of JPanels in each tab in

  • 0

Im basicly trying to add in a bunch of JPanels in each tab in the jtabbedpane, and it works fine on its own. But when following the Javatutorial on adding closingbuttons to each tab, it adds this weird tabContainer to the jtabbedpane after the first(and only the first) adding of a button. I realize Aqua is mac-related but problem still occurs linux and windows..

im basicly doing:

JTabbedPane pane;

this.add("channel",new JTextArea("texttexttext"));

ButtonTabComponent ctb = new ButtonTabComponent(pane);

this.setTabComponentAt(pane.indexOfTab("channel"),ctb);

the first tab also works perfectly, but all the next ones added is beeing pushed one index over because of the AquaTabbedPaneCopyFromBasicUI$TabContainer, as one can see in the screenshot. So when im trying to get them out of the tabbedpane to update some info(check the code linked below) i cant cast it, because the index beeing returned from indexOfTab(Channel), is the index of the aqua..

screenShot of debugging and the array of jtabbedPane: http://server.westman.no/free/Skjermbilde%202011-11-18%20kl.%2012.32.02.png

whats worse is that i cant remove index 2 in the tabbedpane, i just get outOfBoundsException, but i can use getComponent(2),(and thats where i first found the bug, because i can getComponent(title) and it tries to return the Aqua… and then i cant cast it to a singletab object which is what want)

This is a surreal problem which probably looks like some youHaveToHaveDoneSomethingElseWrong, but ive been at this for a week, and after having sevral people looking at it, im no closer to a solution. (It can ofcourse be a gotDamnUrADumbAss problem tough..)

Hope this made sense to someone!

Code in question :
tabHandler : http://apps.netcrawlr.net/p/pastebin.php?show=41

comment if you would like to see something else referenced.

sscce:

    package jtabbedtest;

        import javax.swing.JFrame;
        import javax.swing.JTabbedPane;
        import javax.swing.JTextArea;

        /**
         *
         * @author hallvardwestman
         */
        public class Jtabbedtest {

            /**
             * @param args the command line arguments
             */
            public static void main(String[] args) {
                // TODO code application logic here


                JFrame jf = new JFrame();
                JTabbedPane jt = new JTabbedPane();
         //debugChecks for whats in jtabbedpane       
         Object[] o = jt.getComponents();
                jf.add(jt);

                jt.addTab("a",new JTextArea("a"));
                int tabIndex = jt.indexOfTab("a"); 

                ButtonTabComponent ctb = new ButtonTabComponent(jt);
                jt.setTabComponentAt(tabIndex, ctb);
                /*
                 * adding closebutton
                 */
          //debugChecks for whats in jtabbedpane       
         o = jt.getComponents();
                jf.setVisible(true);

                jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


            }
        }

and just put this : http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/TabComponentsDemoProject/src/components/ButtonTabComponent.java    in a new file called ButtonTabComponent
  • 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-04T19:43:20+00:00Added an answer on June 4, 2026 at 7:43 pm

    Currently im developing app that use JTabbedPane too, and everything works fine for me, adding, removing selected tab, other tab, and all tab.

    First of all, you should – not a must- provide integer variable to hold sum of the tab you already have, let’s say it called tabCount

    code to check if a tab exist in tabbedpane :

    private boolean isTabExist(String title) {
        for (int i = 0; i < tabCount; i++) {
            if (jTabbedPane1.getTitleAt(i).equalsIgnoreCase(title)) {
                jTabbedPane1.setSelectedIndex(i);
                return true;
            }
        }
        return false;
    }
    

    code to insert new tab : (in my app, if that tab is already added, it won’t add again)

    if (!isTabExist("My Tab")) {
            jTabbedPane1.insertTab("My Tab", null, yourCustomPanel, "My tab", tabCount);
            jTabbedPane1.setSelectedIndex(tabCount);
            tabCount = jTabbedPane1.getTabCount();            
        }
    

    to remove selected tab (in any index)

    jTabbedPane1.remove(jTabbedPane1.getSelectedIndex());  // remove selected tab
    tabCount = jTabbedPane1.getTabCount();
    

    Try codes above and tell me if you still getting problem to remove tab at some index…

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

Sidebar

Related Questions

I have an odd problem. Basicly my page works fine however after a small
basicly, I'm trying to show the result of a listview (created with QSLite)but in
maybe its late or something, but this is freaking me out. Basicly im writing
I'm trying to build some GANT script prior to my Grails Plugin. Basicly, i
What I'm trying to do is basicly what this photo shows. When I select
So basicly what I'm trying to accomplish is that foreach row in mysql query
im trying to create ball animation using gdi but i can't get it working.
I'm new to java and am trying to write a simple program that basicly
Basicly i'm trying to create image cropping script, and it's almost done, here is
I'm trying to create a pl/sql block that uses references. Basicly, this is what

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.