8

これらの進行状況バーがあります:

サンプルバー

背景色や進行状況バー自体の色を変更せずに、進行状況バーの TEXT の色を設定しようとしています。私が知る限り、setForeground() はテキストとバーの色の両方を設定しますか? 一方を他方なしで行う方法はありますか?

4

2 に答える 2

21

ああ、UI を変更できるようです。

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

Foreground と Background の使用は直感的ではなかったため、これは少し混乱しました。背景は、バーがテキストを覆っていないときのテキストの色であり、前景は、バーが覆っているときのテキストの色です。

最終結果は次のとおりです。

色調整済み

于 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 に答える