Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top