简体   繁体   English

如何更改jTabbed Pane标头的颜色

[英]How to change the colour of the jTabbed Pane header

I want to change the colour of the jTabbed Pane header(tab headers) and i want to get rid of the line which is separating the tab header and its body. 我想更改jTabbed Pane标头(标签标头)的颜色,并且要摆脱将标签标头及其主体分开的那一行。 I also like to have round edges for Tabbed Pane. 我也喜欢选项卡式窗格的圆边。 How to do all these customization in swing? 如何进行所有这些自定义? Is there any external jars available with this kind of inbuilt gui features. 这种内置的gui功能是否有可用的外部jar。 I don't want to use any look and feel to do this because many of them are also not customizable according to my need. 我不想使用任何外观,因为其中许多也无法根据我的需要进行自定义。 As i am quite new to java please give me a detailed answer. 由于我是Java的新手,请给我详细的答案。 Thanks in advance. 提前致谢。

For more complex look-and-feel changes you should take a look into writing your own look-and-feel like glad3r already mentioned. 对于更复杂的外观更改,您应该像编写的glad3r一样编写自己的外观。 This post also is a great example . 这个帖子也是一个很好的例子

For some basic things you might simply want to change some UIManager values, see example below and play a bit around with those values. 对于一些基本的事情,您可能只想更改一些UIManager值,请参见下面的示例并使用这些值。

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.InsetsUIResource;

@SuppressWarnings("serial")
public class TabbedPaneTest extends JTabbedPane {

    public static void main(String[] args) {

        JFrame frame = new JFrame("TabbedPane");
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setBackground(Color.RED);
        frame.getContentPane().add(new TabbedPaneTest());
        frame.setVisible(true);
    }

    public TabbedPaneTest() {

        UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 0, 0, 0));
        UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(Color.GREEN));
        UIManager.put("TabbedPane.focus", new ColorUIResource(Color.ORANGE));
        UIManager.put("TabbedPane.selected", new ColorUIResource(Color.YELLOW));
        UIManager.put("TabbedPane.darkShadow", new ColorUIResource(Color.DARK_GRAY));
        UIManager.put("TabbedPane.borderHightlightColor", new ColorUIResource(Color.LIGHT_GRAY));
        UIManager.put("TabbedPane.light", new ColorUIResource(Color.WHITE));
        UIManager.put("TabbedPane.tabAreaBackground", new ColorUIResource(Color.CYAN));
        UIManager.put("ToolTip.background", Color.WHITE);
        UIManager.put("ToolTip.border", new BorderUIResource(new LineBorder(Color.BLACK)));
        this.updateUI();

        this.setBackground(Color.BLUE);

        JPanel testPanel = new JPanel();
        testPanel.setLayout(new BorderLayout());
        testPanel.add(new JLabel("Hello World"), BorderLayout.NORTH);
        testPanel.add(new JTextArea("Looks nice out there :)"), BorderLayout.CENTER);

        JPanel testPanel2 = new JPanel();
        testPanel2.setLayout(new BorderLayout());
        testPanel2.add(new JLabel("Good Bye World"), BorderLayout.NORTH);
        testPanel2.add(new JTextArea("AAAAAnnnnnd... I'm gone"), BorderLayout.CENTER);

        this.addTab("Hello World", testPanel);
        this.addTab("BB World", testPanel2);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM