设置 JProgressBar 文本的颜色 [英] Setting the colors of a JProgressBar text

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

问题描述

我有这些进度条:

我正在尝试设置进度条文本的颜色,而不更改背景颜色或进度条本身的颜色.据我所知, setForeground() 设置文本和条形颜色?有没有办法做到一个而没有另一个?

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?

推荐答案

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

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.

这是最终结果:

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

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