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.......??
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);
}
选项卡本身的首选大小由UI委托的嵌套类TabbedPaneLayout
,您可以在其中覆盖preferredTabAreaWidth()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.