我正在程序中尝试配色方案。我可以更改面板和选项卡式选项卡的颜色,但是它们之间有一条细条保持默认颜色
我已经尝试来更改Frame
,content pane
,tabbed-pane
(普通背景和选定背景)和面板的背景颜色。我什至尝试更改边框颜色,但无法解决问题
(我正在使用的颜色只是为了使其更加可见,并且以下代码已从同一java文件的各个部分获取,只是为了显示我正在使用的代码)
//Panel
testPanel.setBackground(Color.red);
testPanel.setBorder(BorderFactory.createLineBorder(Color.green, 3));
//Content pane
Container cp = this.frame.getContentPane();
cp.setBackground(Color.magenta);
//TabbedPane
UIManager.put("TabbedPane.selected", Color.green);
tabbedPane.setBackground(Color.CYAN);
tabbedPane.setBorder(BorderFactory.createLineBorder(Color.black, 3));
我希望背景的颜色可以从主面板无缝地流到活动的选项卡式窗格的标题选项卡(在这种情况下,它是由红色背景和绿色的“测试面板”背景显示的,程序将是一种颜色),但是它被一条默认的细灰色条(甚至在左右两侧和底边的黑色和绿色边框之间)分隔开,甚至到处都是。
下面链接了一张图片,以显示我的意思,因为我了解我的描述可能不太清楚
最低工作示例
下面,灰色区域位于带有黑色边框的蓝色面板和粉红色的内容窗格边框之间以及选项卡下方
public static void main(String[] arg)
{
//create frame
JFrame frame = new JFrame("minimal working code");
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setBounds(200, 200, 500, 300);
frame.setVisible(true);
//change tabbedPane selection colour
UIManager.put("TabbedPane.selected", Color.green);
//create tabbed pane
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(30, 20, 400, 200);
frame.getContentPane().add(tabbedPane);
//create test panels
JPanel panel1 = new JPanel();
tabbedPane.add("Panel 1", panel1);
JPanel panel2 = new JPanel();
tabbedPane.addTab("Panel 2",panel2);
//change colors of panel and tabbed pane background and border
panel1.setBackground(Color.blue);
tabbedPane.setBackground(Color.red);
frame.getContentPane().setBackground(Color.yellow);
panel1.setBorder(BorderFactory.createLineBorder(Color.black,3));
tabbedPane.setBorder(BorderFactory.createLineBorder(Color.pink,3));
}
答案 0 :(得分:3)
答案 1 :(得分:1)
好吧,我花了一些时间找到这个。看起来有人击败了我。
UIManager.put("TabbedPane.contentBorderInsets",
new InsetsUIResource(0, 0, 0, 0));
UIManager.put("TabbedPane.borderHightlightColor", java.awt.Color.yellow); // tab
// UIManager.put("TabbedPane.shadow", java.awt.Color.yellow);
// UIManager.put("TabbedPane.tabAreaBackground", java.awt.Color.yellow);
UIManager.put("TabbedPane.light", java.awt.Color.yellow); // tab
// UIManager.put("TabbedPane.selectHighlight", java.awt.Color.yellow);
// UIManager.put("TabbedPane.highlight", java.awt.Color.yellow);
UIManager.put("TabbedPane.darkShadow", java.awt.Color.yellow);// tab
// UIManager.put("TabbedPane.focus", java.awt.Color.yellow);
// UIManager.put("TabbedPane.lightHighlight", Color.yellow);
// UIManager.put("TabbedPane.selectHighlight", Color.yellow);
上找到有关这些信息的更多信息。