gpt4 book ai didi

java - Swing JTabbedPane如何设置滚动宽度?

转载 作者:行者123 更新时间:2023-12-01 17:31:24 25 4
gpt4 key购买 nike

我使用以下代码创建 JTabbedPane

new JTabbedPane(JTabbedPane.LEFT,JTabbedPane.SCROLL_TAB_LAYOUT);

它会导致滚动的宽度小于选项卡选择区域

enter image description here

如何使滚动宽度更宽以适合选项卡选择区域?

最佳答案

您可以扩展BasicTabbedPaneUI并在createScrollButton()中实现您自己的按钮,提供新的首选尺寸。看起来 BasicTabbedPaneUI 对这些按钮有自己的私有(private)实现 - 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);
}
};
}
}

并设置新的用户界面:

tabbedPane.setUI(new ExtendedTabbedPaneUI());

关于java - Swing JTabbedPane如何设置滚动宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com