SplitXor
SplitXor

Reputation: 165

Remove space/border/margin of JTabbedPane

Image JtabbedPane http://img850.imageshack.us/img850/7339/immaginedya.png

How can i remove the selected margin of a JTabbedPane? :(

Upvotes: 3

Views: 2365

Answers (2)

reconnect
reconnect

Reputation: 11

Use this for disable margins in whole app, or without '.getDefaults()' before you create a new tabbed pane.

    UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0,0,0,0));
    UIManager.getDefaults().put("TabbedPane.tabAreaInsets", new Insets(0,0,0,0));
    UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true);

Upvotes: 1

Mikle Garin
Mikle Garin

Reputation: 10143

Since Nimbus L&F is based on Synth L&F i guess you have to load a custom Synth style for tabbed pane tab area with a custom insets specified (in your case with smaller left/right insets).

You can read about styling synth here: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/synth.html

I guess that style file (you can name it whatever - for e.g. style.xml) should look like this:

<synth>
    <style id="tabAreaStyle">
        <insets top="0" left="0" right="0" bottom="0" />
    </style>
    <bind style="tabAreaStyle" type="region" key="TabbedPaneTabArea" />
</synth>

I found the key TabbedPaneTabArea by looking into SynthTabbedPaneUI source code.

Loading style:

final NimbusLookAndFeel lookAndFeel = new NimbusLookAndFeel ();
lookAndFeel.load ( MyClass.class.getResource ( "style.xml" ) );

Then you can use that L&F:

UIManager.setLookAndFeel ( lookAndFeel );


Edit1: I just checked - this way works only with SynthLookAndFeel, NimbusLookAndFeel seems to be final and cannot be re-styled anyhow. Nimbus painters have hardcoded values (including the tab area insets you want to change).


Edit2: Also in non-Synth L&Fs tab area insets are taken from UIDefaults using TabbedPane.tabAreaInsets key. This might be useful if you will change the L&F in the end...


To summ up:

  1. As i can see from Nimbus source code - you cannot change this margin in tabbed pane
  2. This margin can be easily changed if you use non-Synth L&F
  3. This margin can be easily changed if you use SynthLookAndFeel itself

Upvotes: 2

Related Questions