Nimbus LAF上的JButton背景 [英] JButton background on Nimbus LAF

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

问题描述

我使用Nimbus LAF,并且想要更改简单JButton的背景.

I use Nimbus LAF and I want to change the background of a simple JButton.

JButton jbutton = new JButton("test");
jbutton.setBackground(Color.BLACK);

但是,当我改变外观时,它不起作用,但是在Nimbus中它不起作用.

But it doesn't work, when I change the look and feel it works but it doesn't work in Nimbus.

我该怎么办?

感谢您的帮助.

推荐答案

Nimbus使用Painter绘制不同的样式.默认情况下,按钮具有渐变色而不是单一颜色.请参见按钮: Nimbus默认列表

Nimbus uses Painter to paint the different Styles. By Default the Button has a gradient not a single Color. See Button: Nimbus Defaults List

您可以编写自己的Painter并覆盖默认值.或者,您可以使用"Button.background"键覆盖背景色,并使用默认画笔".

You can write your own Painter and override the default. Or you override the background color with the key "Button.background" and use the Default Painter.

UIDefaults overrides = new UIDefaults();
overrides.put("Button.background", Color.RED);
jbutton.putClientProperty("Nimbus.Overrides", overrides);
jbutton.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
SwingUtilities.updateComponentTreeUI(jbutton);

或者如果您想更改所有按钮的颜色,请尝试:

Or if you want to change the Color for all Buttons, try:

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put("Button.background",  Color.RED);

顺便说一句.如果更改此颜色,则JButton基于Nimbus默认键"nimbusBase":

Btw. The JButton bases on the Nimbus default key "nimbusBase", if you change this color :

UIDefaults defaults = UIManager.getLookAndFeelDefaults();
defaults.put( "nimbusBase", Color.RED );

然后,将使用nimbus defalut-blue或辅助颜色的所有内容更改为新颜色,而不仅仅是按钮.

then you change everything that uses the nimbus defalut-blue or a secondary color into your new color, not only the Buttons.

我找到了一个不错的Nimbus Theme Creator,它可以显示将Nimbus默认颜色更改为所有组件的效果: http://aephyr.googlecode.com/svn/trunk

I found a nice Nimbus Theme Creator, which can show the effect of changing a Nimbus Default Color to all Components: http://aephyr.googlecode.com/svn/trunk

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

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