0

How can I subclass a JTabbedPane and give each instance of my subclass a Look-and-Feel that is different from the default LaF? I still want access to the default JTabbedPanel, so simply overriding the global LaF is not an option.

Thanks.

CtrlF
  • 674
  • 3
  • 8
  • 17

1 Answers1

1

You can manually set the specific UI implementation of the JTabbedPane (and most other JComponents) by calling the setUI(TabbedPaneUI ui) method.

For example to set a specific JTabbedPane to use the Metal Look and Feel use:

JTabbedPane fooPane = new JTabbedPane();
fooPane.setUI(MetalTabbedPaneUI.createUI(fooPane));

When creating a subclass (like you do) of JTabbedPane you will need to override the method updateUI() like this:

public void updateUI() {
    setUI(MetalTabbedPaneUI.createUI(this));
}
Jasper Siepkes
  • 1,412
  • 16
  • 25
  • So, here's what I'm doing in my constructor: `this.setUI(MetalTabbedPaneUI.createUI(this));` And (on OS X) it doesn't appear to have any affect when I use MetalPane instead of JTabbedPane – CtrlF Apr 16 '13 at 21:56
  • Updated my answer for your use-case. Does that help? – Jasper Siepkes Apr 16 '13 at 21:59