如何设置JTabbedPane
选项卡背景和前景、高度和宽度(选中和未选中的选项卡)
问问题
5413 次
3 回答
6
您可以为 UIDefaults 设置新值:
UIDefaults def = UIManager.getLookAndFeelDefaults();
def.put( "TabbedPane.foreground", Color.RED );
def.put( "TabbedPane.textIconGap", new Integer(16) );
def.put( "TabbedPane.background", Color.BLUE );
def.put( "TabbedPane.tabInsets", new Insets(10,10,10,10) );
def.put( "TabbedPane.selectedTabPadInsets", new Insets(10,20,10,20) );
这是密钥列表
TabbedPane.textIconGap
TabbedPane.contentOpaque
TabbedPane.focus
TabbedPane.foreground
TabbedPane.tabRunOverlay
TabbedPane.shadow
TabbedPane.darkShadow
TabbedPane.background
TabbedPane.ancestorInputMap
TabbedPane.focusInputMap
TabbedPane.tabInsets
TabbedPane.light
TabbedPane.contentBorderInsets
TabbedPane.tabsOverlapBorder
TabbedPane.tabsOpaque
TabbedPane.tabAreaInsets
TabbedPane.highlight
TabbedPane.font
TabbedPane.selectedTabPadInsets
对于 Nimbus LookAndFeel,还有一些其他Nimbus 默认值,例如:
TabbedPane:TabbedPaneTabArea.contentMargins
TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
TabbedPane:TabbedPaneTab[Selected].backgroundPainter
TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
TabbedPane:TabbedPaneTab.contentMargins
TabbedPane.tabOverlap
于 2011-08-09T10:13:35.790 回答
2
更改选项卡高度和宽度的一种方法是在选项卡的标签中使用 HTML 和/或 CSS。为此,您可以在 HTML 'span' 或 'p' 元素中使用 CSS 填充属性。
于 2011-10-19T11:44:54.157 回答
2
您可以按如下方式控制高度:
JTabbedPane tabs = new JTabbedPane();
tabs.setUI(new BasicTabbedPaneUI() {
@Override
protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
return 45; // manipulate this number however you please.
}
});
如果每个选项卡需要不同的高度,这个答案也可能有用:How to handle the height of the tab title in JTabbedPane
于 2016-08-04T16:34:45.420 回答