user238033
user238033

Reputation:

Centering the JTabbedPane but not the actual tabs

How would I go about making the length of the tabs automatically resize based on how much room is left in that row of tabs.

Picture:

alt text

As you can see the tab's width is based off the text in the tab.

If you need me to explain what I want better then just ask me because I don't know if I made it clear enough.

Upvotes: 1

Views: 677

Answers (1)

trashgod
trashgod

Reputation: 205835

You can use a custom component and set it's preferred size. For example, in ButtonTabComponent of TabComponentsDemo:

label.setPreferredSize(new Dimension(...));

You have to choose an appropriate dimension based on other aspects of your layout, so it won't be automatic.

I want to define a size for the actual tabbed pan.

The size of the JTabbedPane is a function of the dimensions and LayoutManager of the Container to which it has been added. In the example cited, the default layout of the frame's content pane is BorderLayout, and add(pane) adds it to the center by default.

To accomplish your goal, I see two approaches:

  1. Divide the current width of the enclosing Container among the existing tabs and repaint the tabbed pane, as shown in this example.

  2. Develop your own implementation of TabbedPaneUI and interpret SCROLL_TAB_LAYOUT accordingly.

Upvotes: 1

Related Questions