如何在Nimbus中更改单个JProgressBar的颜色? [英] How to change the color of a single JProgressBar in Nimbus?

查看:94
本文介绍了如何在Nimbus中更改单个JProgressBar的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图改变Nimbus LAF(Look And Feel)中单个JProgressBar的颜色。此解决方案确实有效,但它会更改所有JProgressBars的颜色:/

I'm trying to change the color of a single JProgressBar in Nimbus LAF (Look And Feel). This solution does work, but it changes the colors of ALL JProgressBars :/

    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("nimbusOrange",defaults.get("nimbusBase"));

在此 thread 是另一种单独更改每个JProgressBar颜色的解决方案:

In this thread is another solution to change the color for each JProgressBar individually:

    progress = new JProgressBar();
    UIDefaults defaults = new UIDefaults();
    defaults.put("ProgressBar[Enabled].backgroundPainter", new MyPainter());
    progress.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    progress.putClientProperty("Nimbus.Overrides", defaults);

不幸的是我无法让它工作。我不知道在哪里可以找到MyPainter()的库。所以我尝试用defaults.get(nimbusBase)和Color.red替换这个方法(不知道我在做什么)。也没用。

Unfortunately I can't get it to work. I don't know where to find the libary for "MyPainter()". So I tried replacing this method (without knowing what I'm doing) with "defaults.get("nimbusBase")" and "Color.red". Didn't work either.

推荐答案

1.请你指出哪一个来自

1.can you please to indicate which one from

UIManager.put("ProgressBar.background", Color.orange);
UIManager.put("ProgressBar.foreground", Color.blue);
UIManager.put("ProgressBar.selectionBackground", Color.red);
UIManager.put("ProgressBar.selectionForeground", Color.green);

通知有效 UIDefaults MetalLookAndFeel

2.然后请在 Nimbus默认值

3.然后尝试覆盖 JProgressBar与逻辑和这个画家

这篇关于如何在Nimbus中更改单个JProgressBar的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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