Swing/IndeterminateAnimation のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/IndeterminateAnimation へ行く。
- 1 (2018-12-31 (月) 17:49:12)
- 2 (2019-07-29 (月) 02:31:12)
- 3 (2020-11-26 (木) 11:37:34)
- 4 (2023-01-25 (水) 14:39:20)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: IndeterminateAnimation title: JProgressBarの不確定モードアニメーションを一方向に変更する tags: [JProgressBar, Animation, LookAndFeel] author: aterai pubdate: 2018-12-31T17:42:54+09:00 description: MetalLookAndFeelを適用したJProgressBarの不確定モードアニメーションを跳ね返りではなく左から右への一方向繰り返しに変更します。 image: https://drive.google.com/uc?export=view&id=18dq3XCJzHrT69mJQQafMAz808GvXj2vTPQ --- * 概要 [#summary] MetalLookAndFeelを適用したJProgressBarの不確定モードアニメーションを跳ね返りではなく左から右への一方向繰り返しに変更します。 #download(https://drive.google.com/uc?export=view&id=18dq3XCJzHrT69mJQQafMAz808GvXj2vTPQ) * サンプルコード [#sourcecode] #code(link){{ class OneDirectionIndeterminateProgressBarUI extends BasicProgressBarUI { // @see com/sun/java/swing/plaf/windows/WindowsProgressBarUI.java @Override protected Rectangle getBox(Rectangle r) { Rectangle rect = super.getBox(r); int framecount = getFrameCount() / 2; int currentFrame = getAnimationIndex() % framecount; if (progressBar.getOrientation() == JProgressBar.VERTICAL) { int len = progressBar.getHeight(); len += rect.height * 2; // add 2x for the trails double delta = len / (double) framecount; rect.y = (int) (delta * currentFrame); } else { int len = progressBar.getWidth(); len += rect.width * 2; // add 2x for the trails double delta = len / (double) framecount; rect.x = (int) (delta * currentFrame); } return rect; } } }} * 解説 [#explanation] - 上: デフォルト -- `BasicLookAndFeel`や`MetalLookAndFeel`の不確定モードは矩形が左右に行ったり来たりするアニメーションがデフォルト - 下: `Windows`風 -- `Windows`環境での不確定モードは矩形が左から右への一方向を繰り返すアニメーションがデフォルト -- `WindowsProgressBarUI`の`getBox(...)`メソッドを参考に`BasicProgressBarUI#getBox(...)`メソッドをオーバーライド ---フレーム数を半分にして、「行き」分だけアニメーションを表示する -- 注: 元の`WindowsProgressBarUI`でも、`JProgressBar#setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)`を設定しても不確定モードのアニメーションは右から左へには変化しない https://drive.google.com/file/d/18dq3XCJzHrT69mJQQafMAz808GvXj2vTPQ/view?usp=sharing * 参考リンク [#reference] - [https://stackoverflow.com/questions/53957264/java-swing-indeterminate-jprogressbar-starting-from-the-left-when-reaching-end-i Java swing indeterminate JProgressBar starting from the left when reaching end instead of bouncing - Stack Overflow] - [[JProgressBarの不確定状態でのアニメーションパターンを変更する>Swing/StripedProgressBar]] -- `JProgressBar`全体が不確定モードでアニメーションするよう変更するサンプル - [[JProgressBarのNimbusLookAndFeelにおける不確定状態アニメーションを変更する>Swing/IndeterminateRegionPainter]] -- `NimbusLookAndFeel`で不確定モードのアニメーションを変更するサンプル - [[JProgressBarの進捗方向を右から左に変更する>Swing/InvertedProgressBar]] * コメント [#comment] #comment #comment