更改JTabbedPane中的活动选项卡颜色

use*_*537 1 java swing jtabbedpane

选中后如何更改选项卡的颜色?和它的边界?在这种情况下,它的 Arbitros标签是蓝色的,我怎么能改变这个?我在JTabbedPane 里面使用 JFrame我发现了这个,但它不起作用UIManager.put("TabbedPane.selected", Color.white); 我做错了什么?

public VentanaPrincipal_vista() {

    super("Ventana Principal");

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(1000, 500);
    this.setResizable(false);
    this.setUndecorated(true);
    this.setBackground(Color.BLUE);
    // add tabbedPane and tabs .

    tabs = new JTabbedPane();
    tabs.setBackground(new Color(83, 83, 83));
    tabs.setForeground(new Color(255, 255, 255));
    tabs.setBorder(null);
    UIManager.put("TabbedPane.selected", Color.white);
    this.add(tabs);

    menuBar = new BGMenuBar();
    menuBar.setColor(new Color(83, 83, 83));
    this.setJMenuBar(menuBar);

    menu = new JMenu("File");
    menu.setForeground(Color.white);
    menuBar.add(menu);

    close = new JMenuItem("Close");

    menu.add(close);
    close.addActionListener(this);
    close.setBackground(new Color(83, 83, 83));
    close.setForeground(new Color(255, 255, 255));

    op1 = new JMenuItem("option 1");
    op1.setBackground(new Color(83, 83, 83));
    op1.setForeground(new Color(255, 255, 255));

    menu.add(op1);

    this.setLocationRelativeTo(null);
    this.setVisible(true);

}// end of constructor
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Dip*_*686 6

对我来说,下面的解决方案有效,我只是在创建JTabbedPane对象之前设置UImanager的TabbedPane.selected颜色属性.

 UIManager.put("TabbedPane.selected", Color.red);

      tabbedPane = new JTabbedPane();
Run Code Online (Sandbox Code Playgroud)

请参阅此链接,我相信它也适合您.

http://esus.com/changing-the-color-of-the-selected-tab-of-a-jtabbedpane/


rah*_*cha -2

请从 java 文档中检查 JTabbedPane 的以下方法

http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html#eg

无效 setBackgroundAt(int, 颜色)