How to set JTabbedPane Tab height width background foreground color (Both selected and Unselected Tab)

删除回忆录丶 提交于 2019-12-02 11:14:23

问题


How to set the JTabbedPane Tab background and Foreground, Height and Width (Both selected and Unselected Tab)


回答1:


You can set new values to the 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) );

here are a list of Keys

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

For Nimbus LookAndFeel there are some other Nimbus Defaults like:

      TabbedPane:TabbedPaneTabArea.contentMargins
      TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
      TabbedPane:TabbedPaneTab[Selected].backgroundPainter
      TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter
      TabbedPane:TabbedPaneTab.contentMargins
      TabbedPane.tabOverlap



回答2:


One way to change height and width of tabs is to use HTML and/or CSS in label of tab. You can use CSS padding attribute in HTML 'span' or 'p' element for this purpose.




回答3:


You can control the height as follows:

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.
    }
});

If each tab needs to be a different height, this answer might also be useful: How to handle the height of the tab title in JTabbedPane



来源:https://stackoverflow.com/questions/6994352/how-to-set-jtabbedpane-tab-height-width-background-foreground-color-both-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!