Swing/DisableAnimatedGif のバックアップ(No.7)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/DisableAnimatedGif へ行く。
- 1 (2013-02-25 (月) 00:50:43)
- 2 (2013-03-18 (月) 03:34:51)
- 3 (2015-01-29 (木) 15:40:54)
- 4 (2016-05-31 (火) 14:34:33)
- 5 (2017-09-01 (金) 17:42:18)
- 6 (2018-02-22 (木) 14:07:32)
- 7 (2018-10-15 (月) 13:20:21)
- 8 (2020-10-16 (金) 19:14:04)
- 9 (2022-08-07 (日) 00:15:52)
- 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: DisableAnimatedGif
title: JLabelに表示したAnimated Gifのアニメーションを停止する
tags: [JLabel, Animation, ImageIcon]
author: aterai
pubdate: 2013-02-25T00:50:43+09:00
description: JLabelに表示したAnimated GIFのアニメーションを停止します。
image:
概要
JLabel
に表示したAnimated GIF
のアニメーションを停止します。
Screenshot

Advertisement
サンプルコード
JLabel label2 = new JLabel() {
@Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
if (!isEnabled()) {
infoflags &= ~FRAMEBITS;
}
return super.imageUpdate(img, infoflags, x, y, w, h);
}
};
View in GitHub: Java, Kotlin解説
上記のサンプルでは、JLabel#isEnabled()
がfalse
の場合は、setIcon()
メソッドで設定したAnimated Gif
のアニメーションを停止するなどのテストを行っています。
Default
- デフォルトの
JLabel
では、JLabel#setEnabled(false);
としてもアニメーションは停止しない
- デフォルトの
Override imageUpdate(...)
JLabel#imageUpdate(...)
のinfoflags
からFRAMEBITS
フラグを落とすことでアニメーションを停止JLabel
がリサイズされると?、コマが進んでしまう
setDisabledIcon
- 別途用意した静止画像を使って、
JLabel#setDisabledIcon(...)
を設定 GrayFilter.createDisabledImage(Image)
でアイコンをグレースケール化
- 別途用意した静止画像を使って、
参考リンク
- Duke Images: iconSized
- ImageObserver (Java Platform SE 8)
- ColorConvertOpで画像をグレースケールに変換
- Animated Gifからフレーム画像を抽出する