• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JProgressBarの進捗状況と進捗文字列色を変更する
#navi(../)
#tags(JProgressBar, UIManager, LookAndFeel)
RIGHT:Posted by &author(aterai); at 2014-08-25
* JProgressBarの進捗状況と進捗文字列色を変更する [#d770c436]
`JProgressBar`の進捗状況の色や、それで塗り潰された場合の進捗文字列色を変更します。

#download
#ref(https://lh3.googleusercontent.com/-GXTDLsaFDf0/U_nV4WbEi0I/AAAAAAAACL0/09g79mFs9ZE/s800/ProgressBarSelectionColor.png)

** サンプルコード [#w91da1eb]
#code(link){{
UIManager.put("ProgressBar.foreground", Color.RED);
UIManager.put("ProgressBar.selectionForeground", Color.ORANGE);
UIManager.put("ProgressBar.background", Color.WHITE);
UIManager.put("ProgressBar.selectionBackground", Color.RED);
}}

#code(link){{
progressBar2.setForeground(Color.BLUE);
progressBar2.setBackground(Color.CYAN.brighter());
progressBar2.setUI(new BasicProgressBarUI() {
  @Override protected Color getSelectionForeground() {
    return Color.PINK;
  }
  @Override protected Color getSelectionBackground() {
    return Color.BLUE;
  }
});
}}


** 解説 [#r7e49ee2]
- 上: `Default`
- 中: `UIManager.put(...);`
-- 文字色: `"ProgressBar.foreground"`
-- 背景色: `"ProgressBar.background"`
-- 進捗状況で塗り潰された場合の文字色: `"ProgressBar.selectionForeground"`
-- 進捗状況の塗り潰し色: `"ProgressBar.selectionBackground"`
-- `NimbusLookAndFeel`では、すべて無効
-- `WindowsLookAndFeel`では、`"ProgressBar.background"`が無効
- 下: `BasicProgressBarUI`
-- 文字色: `JProgressBar#setForeground(Color)`で設定
-- 背景色: `JProgressBar#setBackground(Color)`で設定
-- 進捗状況で塗り潰された場合の文字色: `BasicProgressBarUI#getSelectionForeground()`をオーバーライド
-- 進捗状況の塗り潰し色: `BasicProgressBarUI#getSelectionBackground()`をオーバーライド

** 参考リンク [#w59e0975]
- [[JLayerを使ってJProgressBarの色相を変更する>Swing/ColorChannelSwapFilter]]

** コメント [#x26f2761]
#comment