简体   繁体   English

调整选项卡式窗格中的选项卡大小

[英]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... 但标签本身......更清楚我想要的是...... 替代文字
to alter the size of the display tab1 and tab2........ how do i do this.......?? 改变显示tab1和tab2的大小........我该怎么做....... ??

Override calculateTabWidth on your BasicTabbedPaneUI like this: 覆盖BasicTabbedPaneUI calculateTabWidth ,如下所示:

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);
}

选项卡本身的首选大小由UI委托的嵌套类TabbedPaneLayout ,您可以在其中覆盖preferredTabAreaWidth()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM