设置JTabbedPane的背景颜色 [英] Set the Background Color for JTabbedPane

查看:1474
本文介绍了设置JTabbedPane的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Nimbus外观和感觉。我需要更改JTabbedPane中选项卡的背景颜色和前景色,但是在JTabbedPane中没有设置颜色。我尝试了setForeground(),setForegroundAt(),setBackground()和setBackgroundAt()方法,但它不起作用。这是我的代码

I am using Nimbus Look and feel. I needs to change the Background color and foreground color of the tab in JTabbedPane but the color doesn't set in JTabbedPane. I tried setForeground(), setForegroundAt(), setBackground() and setBackgroundAt() methods but it isnt works.This is my code


public class TabbedPaneDemo extends JFrame
{
    TabbedPaneDemo()
    {
        try
        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        }
        catch(Exception ex) {}

}

推荐答案

您可以做一些不同的事情,具体取决于您对确切颜色的控制程度。最简单的方法是更改​​UIManager中的一些属性,以更改Nimbus从其他颜色中获取的颜色。我用你的代码玩了一下,发现如果我在调用UIManager.setLookAndFeel()之后输入以下代码,它会接近你在你的例子中尝试的黑色外观:

There are a few different things you can do, depending upon how much control you want over the exact color. The easiest way is to change some of the properties in the UIManager to change the colors that Nimbus derives its other colors from. I played around a little with your code, and found that if I put the following code after the call to UIManager.setLookAndFeel(), it would approximate the red-on-black look you attempted in your example:

     UIManager.put("nimbusBase", new ColorUIResource(0, 0, 0));
     UIManager.put("textForeground", new ColorUIResource(255, 0, 0));

我会留给你试验。有关实验的更多信息,有一篇关于配置Nimbus 这里的文章很好。请务必查看标题为Nimbus UIDefaults Properties List的链接。除了将颜色按摩到类似于你想要的颜色之外,你将不得不开始做一些混乱的事情,比如实现自定义绘画的Painter类。

I'll leave it to you to experiment. For more information to experiment with, there is a good article on configuring Nimbus here. Be sure you look at his link titled "Nimbus UIDefaults Properties List". Outside of just massaging the colors to something similar to what you want, you'll have to start doing messy things like implementing Painter classes that do custom painting.

这篇关于设置JTabbedPane的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆