Swing/IndeterminateRegionPainter のバックアップ(No.11)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/IndeterminateRegionPainter へ行く。
- 1 (2014-06-30 (月) 15:57:20)
- 2 (2014-07-14 (月) 00:16:34)
- 3 (2014-10-11 (土) 16:55:44)
- 4 (2015-11-11 (水) 20:04:21)
- 5 (2017-05-09 (火) 17:57:00)
- 6 (2017-07-24 (月) 20:08:17)
- 7 (2018-07-24 (火) 17:52:42)
- 8 (2020-07-25 (土) 03:47:29)
- 9 (2021-12-21 (火) 16:28:59)
- 10 (2025-01-03 (金) 08:57:02)
- 11 (2025-01-03 (金) 09:01:23)
- 12 (2025-01-03 (金) 09:02:38)
- 13 (2025-01-03 (金) 09:03:21)
- 14 (2025-01-03 (金) 09:04:02)
- category: swing
folder: IndeterminateRegionPainter
title: JProgressBarのNimbusLookAndFeelにおける不確定状態アニメーションを変更する
tags: [JProgressBar, UIDefaults, Painter, NimbusLookAndFeel, Animation]
author: aterai
pubdate: 2014-06-30T15:57:20+09:00
description: JProgressBarをNimbusLookAndFeelで使用している場合、その不確定状態アニメーションを変更します。
image:
Summary
JProgressBar
をNimbusLookAndFeel
で使用している場合、その不確定状態アニメーションを変更します。
Screenshot

Advertisement
サンプルコード
UIDefaults d = new UIDefaults();
d.put("ProgressBar[Enabled+Indeterminate].foregroundPainter",
new AbstractRegionPainter() {
// ...
private final PaintContext ctx = new PaintContext(
new Insets(5, 5, 5, 5), new Dimension(29, 19), false);
@Override public void doPaint(
Graphics2D g, JComponent c, int width, int height,
Object[] extendedCacheKeys) {
path = decodePath1();
g.setPaint(color17);
g.fill(path);
rect = decodeRect3();
g.setPaint(decodeGradient5(rect));
g.fill(rect);
rect = decodeRect4();
g.setPaint(decodeGradient6(rect));
g.fill(rect);
}
@Override public PaintContext getPaintContext() {
return ctx;
}
// ...
});
progress = new JProgressBar(model);
progress.putClientProperty("Nimbus.Overrides", d);
View in GitHub: Java, Kotlin解説
上記のサンプルでは、NimbusLookAndFeel
でJProgressBar
の不確定状態を表現するアニメーションを変更するために、セルの描画を行うAbstractRegionPainter#doPaint(...)
をオーバーライドしたPainter
を作成し、これをUIDefaults
に設定しています。
AbstractRegionPainter#doPaint(...)
の中身はProgressBarPainter#paintForegroundEnabled(...)
と同等だが、このメソッドや関連するProgressBarPainter#decodePath1()
などのメソッドはprotected
ではなくすべてprivate
のためペインターごとコピーすることで対応