【发布时间】:2020-05-20 21:48:25
【问题描述】:
我正在使用 JTabbedPane 设计以下布局,并希望更改突出显示部分的颜色。但我没有办法做到这一点。
我的问题
如何更改其背景颜色?
我尝试了什么?
我尝试更改 JPanel 和 JTabbedPane 的 background-color 和 Foreground-color,但没有成功。
我也试过这个,同时将Opaque = false 保留在属性中,但没有运气。jTabbedPane1.setForegroundAt(1, Color.yellow);
jTabbedPane1.setForegroundAt(2, Color.yellow);
String[] tabNames = {"Signin", "General", "Call Rate", "Audio Device","tab 5","tab 6","tab 7","tab 8","tab 9"};
for (int i = 0; i < tabNames.length; i++) {
JLabel lab = new JLabel("<html><font color=white>" + tabNames[i] + "</font></html>", SwingConstants.CENTER);
lab.setForeground(Color.red);
lab.setBackground(Color.BLUE);
lab.setPreferredSize(new Dimension(200, 50));
lab.setFont(new Font("Times New Roman", Font.BOLD, 22));
jTabbedPane1.setTabComponentAt(i, lab);
}
for (int i = 0; i < this.jTabbedPane1.getTabCount(); i++) {
jTabbedPane1.setBackgroundAt(i,Color.DARK_GRAY);
}
我尝试添加JLabel 以更改出现我的选项卡名称的组件的大小,然后尝试设置setBackgroundAt。它和setBackground 和setForeground 在标签上都不起作用。
我的外观和感觉
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Settings.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
【问题讨论】:
-
您是要更改标签的颜色,还是标签所在的“托盘”?
-
@VGR 显示登录、常规等标签名称的托盘
-
@VGR 我用我之前定义的以外的尝试更新了这个问题。请看一下
-
你试过setBackgroundAt吗?
-
@VGR 请查看更新后的问题
标签: java swing jpanel jtabbedpane