设置 JProgressBar 文本的颜色

发布于 2024-09-14 03:25:57 字数 210 浏览 9 评论 0原文

我有这些进度条:

Sample Bars

我正在尝试设置进度文本的颜色条,而不改变背景颜色或进度条本身的颜色。据我所知, setForeground() 设置文本和条形颜色?有没有一种方法可以做到一举两得?

I have these progress bars:

Sample Bars

I'm trying to set the color of the TEXT of the progress bars, without changing the background color or the color of the progress bar itself. As far as I can tell, setForeground() sets both the text and the bar color? Is there a way to do one without the other?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-09-21 03:25:57

啊哈 - 看起来我可以修改 UI:

    setUI(new BasicProgressBarUI() {
      protected Color getSelectionBackground() { return Color.black; }
      protected Color getSelectionForeground() { return Color.white; }
    });

这有点令人困惑,因为前景和背景的使用并不直观。背景是条未覆盖文本时的文本颜色,前景是条覆盖文本时的文本颜色。

这是最终结果:

颜色调整

Ah ha - looks like I can modify the UI:

    setUI(new BasicProgressBarUI() {
      protected Color getSelectionBackground() { return Color.black; }
      protected Color getSelectionForeground() { return Color.white; }
    });

This was a bit confusing, since the use of Foreground and Background weren't intuitive. Background is the color of the text when the bar isn't covering it, foreground is the color of the text when it is.

Here's the end result:

Colors adjusted

Saygoodbye 2024-09-21 03:25:57

通过带有 UIDefaults 的消息,

ProgressBar.background is the background color
ProgressBar.foreground is the cell color
ProgressBar.selectionBackground is the text color outside cells
ProgressBar.selectionForeground is the text colot INSIDE cells

UIManager.put("ProgressBar.selectionForeground", Color.black);
UIManager.put("ProgressBar.selectionBackground", Color.black);

By message with UIDefaults,

ProgressBar.background is the background color
ProgressBar.foreground is the cell color
ProgressBar.selectionBackground is the text color outside cells
ProgressBar.selectionForeground is the text colot INSIDE cells

UIManager.put("ProgressBar.selectionForeground", Color.black);
UIManager.put("ProgressBar.selectionBackground", Color.black);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文