2016-07-13 30 views
1

我正在自定義我的JTabbedPane的視覺外觀,其中包含三個JTables更改Tab和JTable之間的線條顏色

雖然我成功着色選項卡的顏色,包括更改文本顏色,但我通過創建自己的BasicTabbedPaneUI更改了選項卡邊框顏色。但仍然有一條線路保持原來的狀態。該行位於選項卡和表格之間。見下圖:

enter image description here

我說的是標有三個豆蔻紅點線。 這條線是什麼?如果它是邊界,它屬於哪裏?我沒有找到設置顏色的方法。我檢查了JTable,他JTabbedPane,甚至JTabbedPane的組件。

只是爲了顯示,我能夠訪問什麼,我繪製每個組件綠色。 enter image description here

你可以看到,這條藍線仍然存在。 有誰知道如何改變顏色? 刪除它將是另一個可以接受的選擇。

回答

3

可能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); 
    }); 
    } 
} 
+0

太棒了!它與設置'UIManager.put(「TabbedPane.contentAreaColor」,Color.GREEN);' – KJaeg