【问题标题】:Change Color of Line between Tab and JTable更改 Tab 和 JTable 之间的线条颜色
【发布时间】:2016-07-13 14:55:00
【问题描述】:

我正在自定义我的JTabbedPane 的视觉外观,其中包含三个JTables

虽然我成功地为选项卡的选择颜色着色,包括更改文本颜色,但我通过创建自己的BasicTabbedPaneUI 更改了选项卡边框颜色。但是仍然有一条线,保持原样。这条线位于选项卡和表格之间。见下图:

我所说的线标有三个小红点。 这条线是什么?如果是边界,它属于哪里?我没有找到设置它的颜色的方法。我检查了JTable,他JTabbedPane,甚至JTabbedPane的组件。

为了展示我能够访问的内容,我将每个组件都涂成了绿色。

您可以看到,这条蓝线仍然存在。 有谁知道如何改变它的颜色? 删除它是另一个可接受的选择。

【问题讨论】:

    标签: java swing jtable jtabbedpane border-color


    【解决方案1】:

    可能是TabbedPane.contentAreaColorTabbedPane.contentBorderInsets 的顶部):

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.plaf.basic.*;
    
    public final class BasicTabbedPaneColorTest {
      private JComponent makeUI() {
        //UIManager.put("TabbedPane.contentBorderInsets",  new Insets(10, 10, 10, 10));
        //UIManager.put("TabbedPane.contentBorderInsets",  new Insets(0, 10, 10, 10));
    
        UIManager.put("TabbedPane.contentAreaColor", Color.GREEN);
        UIManager.put("TabbedPane.highlight",        Color.RED);
    
        JTabbedPane tabs = new JTabbedPane();
        tabs.setUI(new BasicTabbedPaneUI());
        //tabs.setBackground(Color.ORANGE);
        //tabs.setOpaque(true);
    
        tabs.addTab("JTable", new JScrollPane(new JTable(20, 3)));
        tabs.addTab("JTree",  new JScrollPane(new JTree()));
        return tabs;
      }
      public static void main(String... args) {
        EventQueue.invokeLater(() -> {
          JFrame f = new JFrame();
          f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          f.getContentPane().add(new BasicTabbedPaneColorTest().makeUI());
          f.setSize(320, 240);
          f.setLocationRelativeTo(null);
          f.setVisible(true);
        });
      }
    }
    

    【讨论】:

    • 太棒了!它适用于设置UIManager.put("TabbedPane.contentAreaColor", Color.GREEN);
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多