如何设置JTabbedPane
标签背景和前景,高度和宽度(选中和未选中标签)
答案 0 :(得分:5)
您可以为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 Defaults喜欢:
TabbedPane:TabbedPaneTabArea.contentMargins
TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
TabbedPane:TabbedPaneTab[Selected].backgroundPainter
TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
TabbedPane:TabbedPaneTab.contentMargins
TabbedPane.tabOverlap
答案 1 :(得分:1)
更改标签高度和宽度的一种方法是在标签的标签中使用HTML和/或CSS。为此,您可以在HTML“span”或“p”元素中使用CSS填充属性。
答案 2 :(得分:0)
您可以按如下方式控制高度:
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