java - 更改 Tab 和 JTable 之间的线条颜色

标签 java swing colors jtable jtabbedpane

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

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

enter image description here

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

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

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

最佳答案

可能 TabbedPane.contentAreaColor(TabbedPane.contentBorderInsets 的顶部):

enter image description here

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

关于java - 更改 Tab 和 JTable 之间的线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38355163/

相关文章:

java - 为什么图像不显示?

java - 通过 Swing 按钮停止线程

java - android.view.InflateException : Binary XML file line #0: Error inflating class null

java - 保存数组数据

java - 正则表达式量词和字符类

java - 为并发 GC 指定额外的 GC 有什么意义吗?

java - 从外部访问 JFrame 内容

ios - 如何在ios中选择显示联系人

css - Twitter 如何从图像像素数据中提取有意义的主题颜色?

r - 在 Windows 上运行的 R/RStudio 中,我们可以让 message()、warning() 和 error() 在控制台中使用不同的颜色吗?