我使用以下代码创建一个 JTabbedPane
new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);
它导致滚动宽度小于选项卡选择区域
如何使滚动宽度更宽以适合选项卡选择区域?
我使用以下代码创建一个 JTabbedPane
new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);
它导致滚动宽度小于选项卡选择区域
如何使滚动宽度更宽以适合选项卡选择区域?
您可以扩展BasicTabbedPaneUI
和实现您自己的按钮以createScrollButton()
提供新的首选尺寸。看起来BasicTabbedPaneUI
这些按钮有自己的私有实现 - ScrollableTabButton
. 您可以创建类似的东西,如下所示:
public class ExtendedTabbedPaneUI extends BasicTabbedPaneUI {
@Override
protected JButton createScrollButton(int direction) {
if (direction != SOUTH && direction != NORTH && direction != EAST &&
direction != WEST) {
throw new IllegalArgumentException("Direction must be one of: " +
"SOUTH, NORTH, EAST or WEST");
}
//return new ScrollableTabButton(direction);
return new BasicArrowButton(direction,
UIManager.getColor("TabbedPane.selected"),
UIManager.getColor("TabbedPane.shadow"),
UIManager.getColor("TabbedPane.darkShadow"),
UIManager.getColor("TabbedPane.highlight")) {
@Override
public Dimension getPreferredSize() {
int maxWidth = calculateMaxTabWidth(JTabbedPane.LEFT);
return new Dimension(maxWidth, super.getPreferredSize().height);
}
};
}
}
并设置新的 UI:
tabbedPane.setUI(new ExtendedTabbedPaneUI());