如何设置JTabbedPane选项卡高度宽度背景前景色(选定和未选定的选项卡)

发布于 2024-11-28 18:33:24 字数 63 浏览 1 评论 0原文

如何设置 JTabbedPane 选项卡背景和前景、高度和宽度(选定和未选定的选项卡)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘和柠 2024-12-05 18:33:24

您可以为 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) );

这里是 Nimbus LookAndFeel 的键列表,

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 默认值例如:

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

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
寒尘 2024-12-05 18:33:24

更改选项卡高度和宽度的一种方法是在选项卡标签中使用 HTML 和/或 CSS。为此,您可以在 HTML“span”或“p”元素中使用 CSS padding 属性。

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.

不顾 2024-12-05 18:33:24

您可以按如下方式控制高度:

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

如果每个选项卡需要不同的高度,这个答案也可能有用:如何处理 JTabbedPane 中选项卡标题的高度

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文