8

我有这些进度条:

样板

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

4

2 回答 2

21

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

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

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

这是最终结果:

调整颜色

于 2010-08-13T21:29:05.110 回答
4

通过带有 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);
于 2011-03-05T16:14:35.987 回答