Resizing tabs in a tab bar

I have a tabbed panel, I want to resize the tabs ... not the whole tabbed panel and not the panels added to it. But the tabs themselves ... clearer what I want ... alt text
resize tabs display1 and tab2 ........ how to do it ....... ??

+3
source share
2 answers

Cancel calculateTabWidthto BasicTabbedPaneUIas follows:

public static void main(String[] args) throws Exception {

    JTabbedPane tabs = new JTabbedPane(JTabbedPane.LEFT);
    tabs.setUI(new BasicTabbedPaneUI() {
        @Override
        protected int calculateTabWidth(
                int tabPlacement, int tabIndex, FontMetrics metrics) {
            return 200; // the width of the tab
        }
    });

    tabs.add("Tab 1", new JButton());
    tabs.add("Tab 2", new JButton());

    JFrame frame = new JFrame("Test");
    frame.add(tabs);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 300);
    frame.setVisible(true);
}
+5
source

The preferred size of the tabs themselves is determined by the nested delegate class of the UI TabbedPaneLayout, in which you can override preferredTabAreaWidth().

+1
source

Source: https://habr.com/ru/post/1781105/


All Articles