3

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

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

nachokk
  • 14,363
  • 4
  • 24
  • 53
SplitXor
  • 165
  • 1
  • 10
  • 1
    i tried with: UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); but the result is: http://img40.imageshack.us/img40/4384/immagine2hk.png – SplitXor May 14 '13 at 14:51

2 Answers2

2

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
Mikle Garin
  • 10,083
  • 37
  • 59
  • See the last few paragraphs i have added into the answer. – Mikle Garin May 14 '13 at 15:34
  • for every L&F is possible by override whole TabbedPaneUI, because most of methods are protected, then not accesible from outside, or by using dirty hack with side effects (I.m posted here one attempt) – mKorbel May 14 '13 at 16:09
  • I'd suggest to use Look and Feels that override JTabbedPane by add/restrict/remove/allows access to part of methods they are not accesible from Standard Java Look And Feel, correct answer will be CardLayout with JButtons added to JList or JScrollBar, then is possible everything that you want to do – mKorbel May 14 '13 at 16:19
1

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);
reconnect
  • 11
  • 1