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:
Divide the current width of the enclosing Container
among the existing tabs and repaint the tabbed pane, as shown in this example.
Develop your own implementation of TabbedPaneUI
and interpret SCROLL_TAB_LAYOUT
accordingly.