2

When using a JTabbedPane, how do you indent the tabs?

Swing default output:

-------  ---------  ------
|  A  |  |   B   |  |  C |
------------------------------
|                            |
|                            | 
|                            |
|                            |
|                            |

Desired indented output:

   -------  ---------  ------
   |  A  |  |   B   |  |  C |
------------------------------
|                            |
|                            | 
|                            |
|                            |
|                            |

This seems simple enough, but I have not been able to find the solution. Thanks.

brian_d
  • 11,190
  • 5
  • 47
  • 72
  • Do you mean that you have two tabbed panes and you want the first tab in the second tabbed pane to be "indented" w.r.t. the first tab of the first tabbed pane? – Geoffrey Zheng Sep 07 '10 at 19:26
  • Just one tabbedpane. I have edited my question to add clarification. – brian_d Sep 07 '10 at 19:48

2 Answers2

1

For all tabbed panes you can use the following with the default LAF:

UIManager.put("TabbedPane.tabAreaInsets", new Insets(2, 20, 0, 6) );

See also: UIManager Defaults

For individual tabbed panes you would probably need to override the "getTabAreaInsets()" method of the BasicTabbedPaneUI class to return the above Inset.

camickr
  • 321,443
  • 19
  • 166
  • 288
0

If there's no way to do it with a simple JTabbedPane, you could use the following (slightly inelegant) solution:

Create your own component, consisting of a JTabbedPane and a JPanel. The JTabbedPane displays only the tabs; as far as it's concerned, each tab is empty. The JPanel (using a CardLayout) is responsible for actually displaying each tab. Add a ChangeListener to the JTabbedPane, and use it to switch between cards of the CardLayout.

Then all you have to do is lay out the JTabbedPane and the JPanel in your own component, which you can do however you like. That lets you push the tabs over to the right.

Etaoin
  • 8,444
  • 2
  • 28
  • 44