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

sas*_*har 3 java user-interface swing awt

我有一个选项卡式窗格,我想调整选项卡的大小......不是整个选项卡式窗格,也不是添加了面板.但标签本身......更清楚我想要的是...... 替代文字
改变显示tab1和tab2的大小........我该怎么做....... ??

dac*_*cwe 5

覆盖calculateTabWidth你的 BasicTabbedPaneUI是这样的:

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);
}
Run Code Online (Sandbox Code Playgroud)