Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resizing the tabs in a tabbed pane

I have a tabbed pane, i want to resize the tabs...... not the entire tabbed pane and nor the panels added to it. But the tabs themselves.... more clearly what i want is... alt text
to alter the size of the display tab1 and tab2........ how do i do this.......??

like image 725
sasidhar Avatar asked Dec 31 '25 01:12

sasidhar


1 Answers

Override calculateTabWidth on your BasicTabbedPaneUI like this:

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);
}
like image 159
dacwe Avatar answered Jan 02 '26 14:01

dacwe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!