Java- 改变秋千背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/200106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java- Changing swing background colour?
提问by dalyons
Ok so ive got a swing app going using the "System" look and feel. Now, I want to change the background colour of the main panels to black. Too easy right?
好的,我得到了一个使用“系统”外观和感觉的 Swing 应用程序。现在,我想将主面板的背景颜色更改为黑色。太容易了吧?
UIManager.put("Panel.background", Color.BLACK);
Well yeah, except now the controls in the app look stupid, because their 'shadows', for want of a better word, are graduated to fade towards the old system default colour(gross windows grey). So there are light grey 'corners' on all the controls, especially the tabs on JTabbedPane. I know it can be fixed, because if you change the windowsXP theme to one with a different default application colour, the controls take on this changed colour and their shadows 'fade' towards it.
嗯,是的,除了现在应用程序中的控件看起来很愚蠢,因为它们的“阴影”,为了更好的词,渐变为向旧系统默认颜色(总窗口灰色)渐变。所以所有控件上都有浅灰色的“角”,尤其是 JTabbedPane 上的选项卡。我知道它可以修复,因为如果您将 windowsXP 主题更改为具有不同默认应用程序颜色的主题,则控件会采用这种更改后的颜色,并且它们的阴影会“淡化”。
But I have no idea what UIManager key it is, or even if you can do it with UIManger.
但我不知道它是什么 UIManager 键,或者即使你可以用 UIManger 来做到这一点。
I dont really want to change the L&F engine, because apart from this it looks good.
我真的不想改变 L&F 引擎,因为除此之外它看起来不错。
回答by RodeoClown
You can see what the default settings (and their keys) are by using UIManager.getDefaults(); You can then iterate over the resulting keySet (it is an instance of Map).
您可以使用 UIManager.getDefaults(); 查看默认设置(及其键)。然后您可以迭代生成的 keySet(它是 Map 的一个实例)。
So something like this will show all the default keys:
所以这样的事情将显示所有默认键:
for (Object key: UIManager.getDefaults().keySet())
{
System.out.println(key);
}
回答by RodeoClown
You might try these:
你可以试试这些:
- control
- controlDkShadow
- controlHighlight
- controlLtHighlight
- controlShadow
- 控制
- 控制DkShadow
- 控制高亮
- controlLtHighlight
- 控制阴影
(I just found them in this list: Swing [Archive] - UIManager: setting background and JScrollBar)
(我刚刚在这个列表中找到它们:Swing [Archive] - UIManager: setting background and JScrollBar)
回答by Rastislav Komara
In general this is a little bit tricky. It depends on exact LaF you are using.
一般来说,这有点棘手。这取决于您使用的确切 LaF。
For example. JGoodies use own color scheme which redefine this stuff.
例如。JGoodies 使用自己的配色方案重新定义这些东西。
In general the property names are composed like
一般来说,属性名称的组成如下
COMPONENT_NAME_WITHOUT_J + '.' + PROPERTY.
Unfortunately, property names can be only obtained from implementation classes of LaF. These aren't shared or something. Each component has its own. Or better, it depends on laziness of author which pairs he used. In general.
不幸的是,属性名称只能从 LaF 的实现类中获得。这些不是共享的。每个组件都有自己的组件。或者更好,这取决于作者使用了哪些对的懒惰。一般来说。
A lot of help makes redefine Panel.* and Button.. A lot of components use Button.properties.
很多帮助使得重新定义 Panel.* 和 Button。. 很多组件都使用Button。特性。
Try, play, win :). I wish you luck :).
尝试,玩,赢:)。祝你好运 :)。
PS: It is a lot of properties to overwrite. But this is the way how LaFs works.
PS:要覆盖的属性很多。但这就是 LaFs 的工作方式。
回答by Craigo
Some controls like JButton need to have setOpaque(false)
called to allow the new background colors to fade through.
需要setOpaque(false)
调用一些控件(如 JButton)以允许新的背景颜色淡入淡出。
回答by gtiwari333
To list out all the possible options that we can set to UIManager to change LaF, run the code below ........
要列出我们可以设置到 UIManager 以更改 LaF 的所有可能选项,请运行以下代码........
import java.util.*;
import javax.swing.UIManager;
public class UIManager_All_Put_Options
{
public static void main (String[] args)
{
Hashtable properties = UIManager.getDefaults();
Enumeration keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
Object value = properties.get (key);
System.out.printf("%-40s \t %-200s \n", key,value);
}
}
}
enjoy...
请享用...