gpt4 book ai didi

java - 更改 JTabbedPane 侧 View 的颜色

转载 作者:太空宇宙 更新时间:2023-11-04 09:07:20 24 4
gpt4 key购买 nike

我使用 JTabbedPane 设计了以下布局,并且想要更改突出显示部分的颜色。但我没有办法做到这一点。
我的问题
如何改变其背景颜色?
我尝试了什么?
我尝试更改 background-colorForeground-color JPanel 和 JTabbedPane 都有,但没有运气。
我也尝试过这个,同时保留 Opaque = false来自属性,但没有运气。
jTabbedPane1.setForegroundAt(1, Color.yellow);
jTabbedPane1.setForegroundAt(2, Color.yellow);

this layout
更新1

 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 。它既不起作用,也不起作用 setBackgroundsetForeground致力于标签工作。
我的外观和感觉

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

最佳答案

基本逻辑是:

JPanel tab1 = new JPanel();
tab1.background( Color.RED );

JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.add(tab1, "Tab1");

JPanel parent = new JPanel( new BorderLayout() );
parent.setBackground( Color.GREEN );
parent.add( tabbedPane );

frame.add( parent );

现在选项卡占据的区域将具有“父”面板的背景颜色。

如果这不起作用,则说明您遇到了外观问题。

解决方案更改外观后问题得到解决

关于java - 更改 JTabbedPane 侧 View 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60068019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com