views:

43

answers:

1

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.

+1  A: 

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.

trashgod
I don't want to define a size for the tabs in the tabbed pane. I want to define a size for the actual tabbed pan.
Gnarly
@Gnarly: I've elaborated above.
trashgod
Thanks but the things you listed are a bit too overkill for something so simple. I guess it doesn't really matter if I make my tabbed pan like this anyways.
Gnarly
@Gnarly: The design lets you easily use a custom tab component with its own layout; try changing the layout for `ButtonTabComponent` to see the effect. `JTabbedPane` doesn't let you change the inter-tab layout, as it must handle side-scrolling itself.
trashgod