2

well first of all let me explain what i mean, and what I'm intending to do, I already know (and did) that in order to modify the appearance of the tabs in a TabbedPane, i need to extend XTabbedPaneUI (X = Basic,or any TabbedPaneUI you wish to extend) and override certain methods of the tabbedPaneUI, and set the new UI as the UI that my tabbedPane is going to use (myTabbedPane.setUI(new MyNewTabbedPaneUI());), for example, in the extension of the ui I can do this:

    @Override
    protected void paintTabBackground( Graphics g, int tabPlacement,int tabIndex, int x, int y, int w, int h, boolean isSelected ) {        
        Color bgColor = tabPane.getBackgroundAt(tabIndex); 
        //tabPane is the way the BasicTabbedPaneUI makes reference to the JTabbedPane that is making use of him
        //Do the painting of the tab background
    }

the first line inside the method (and the only one) will return the background color I set on the tab that is going to be painted (myTabbedPane.setBackgroundAt(0, desiredColor);) and then I can work with that color inside my own implementation of TabbedPaneUI, but what should I do in order to add more information to each tab, for example the percent of background I want to be painted, or any kind of info that is not (it can't be) stored in the implementation of TabbedPaneUI, because is dynamic and depends on each individual tab, so I thought, well lets add that info inside each individual tab, and then realize that I don't know which kind of object a tab is and I have not been able to find out anywhere what kind of object a tab is, I'm afraid there is not such thing as a tab object in java, so any help to find that out, or to achieve what I'm trying to do? (add more information to each tab, or to the JTabbedPane itself in order to have more data to work with while painting the tabs?)

P.S: I know it might be a bit confusing, so please any doubt about what I'm trying to explain just comment

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
Ordiel
  • 2,442
  • 3
  • 36
  • 52

1 Answers1

2

I would consider extending the TabbedPaneUI a last resort.

  • You can set the tab's background color, as shown here.

  • You can condition the pane's background color, as shown here.

  • You can replace the tab component entirely, as shown in the TabComponentsDemo.

Note that the tab component must be opaque.

imqge

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I'm entirely agree with what you're saying, but this does not answer my question, which is how to add more information to each tab so I can modify the way each individual tab is being painted? – Ordiel Nov 12 '12 at 23:20
  • Until you invoke `setTabComponentAt()`, `getTabComponentAt()` returns `null`, which indicates that the UI delegate renders the tab component. I'd store any context in the component you pass to `setTabComponentAt()`, as shown in the `ButtonTabComponent` class in the `TabComponentsDemo` cited above. – trashgod Nov 12 '12 at 23:39