Search code examples
javaswingcolorsjtablejtabbedpane

Change Color of Line between Tab and JTable


I am customizing the visual appearance of my JTabbedPane, which contains three JTables.

While I was successfully coloring the selection color of the tab, including a changing of the text color, I changed the tab border colors by creating an own BasicTabbedPaneUI. But there is still one line, which remained in the way it was. This line is located between the tab and the table. See the following picture:

enter image description here

The line I am talking about is marked with three litte red dots. What is this line? If it is a border, where does it belong to? I didn't find a way to set its color. I checked the JTable, he JTabbedPane, and even the components of the JTabbedPane.

Just to show, what I am able to access, I painted every component green. enter image description here

You can see, that this blue line still remains. Does anyone know how to change its color? Removing it would be another acceptable option.


Solution

  • Probably TabbedPane.contentAreaColor(top of the 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);
        });
      }
    }