• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JLabelに表示したAnimated Gifのアニメーションを停止する
#navi(../)
#tags(JLabel, Animation, ImageIcon)
RIGHT:Posted by &author(aterai); at 2013-02-25
*JLabelに表示したAnimated Gifのアニメーションを停止する [#g1d82430]
``JLabel``に表示した``Animated Gif``のアニメーションを停止します。
---
category: swing
folder: DisableAnimatedGif
title: JLabelに表示したAnimated Gifのアニメーションを停止する
tags: [JLabel, Animation, AnimatedGif, ImageIcon]
author: aterai
pubdate: 2013-02-25T00:50:43+09:00
description: JLabelに表示したAnimated GIFのアニメーションを停止します。
image: https://lh6.googleusercontent.com/-pYT15pLG7KY/USoyuJzLxUI/AAAAAAAABfo/JgO7-MbsL5U/s800/DisableAnimatedGif.png
---
* 概要 [#summary]
`JLabel`に表示した`Animated GIF`のアニメーションを停止します。

-&jnlp;
-&jar;
-&zip;
#download(https://lh6.googleusercontent.com/-pYT15pLG7KY/USoyuJzLxUI/AAAAAAAABfo/JgO7-MbsL5U/s800/DisableAnimatedGif.png)

//#screenshot
#ref(https://lh6.googleusercontent.com/-pYT15pLG7KY/USoyuJzLxUI/AAAAAAAABfo/JgO7-MbsL5U/s800/DisableAnimatedGif.png)

**サンプルコード [#fde5e06a]
* サンプルコード [#sourcecode]
#code(link){{
JLabel label2 = new JLabel() {
  @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
    if(!isEnabled()) {
    if (!isEnabled()) {
      infoflags &= ~FRAMEBITS;
    }
    return super.imageUpdate(img, infoflags, x, y, w, h);
  }
};
}}

**解説 [#g5035119]
上記のサンプルでは、``JLabel``が``Enabled``でない場合にアニメーションを停止するよう設定しています。
* 解説 [#explanation]
上記のサンプルでは、`JLabel#isEnabled()`が`false`の場合は`setIcon()`メソッドで設定した`Animated Gif`のアニメーションを停止するなどのテストを行っています。

- ``Default``
-- デフォルトの``JLabel``では、``JLabel#setEnabled(false);``としてもアニメーションは停止しない
- ``Override imageUpdate(...)``
-- ``JLabel#imageUpdate(...)``の``infoflags``から``FRAMEBITS``フラグを落とすことでアニメーションを停止
-- ``JLabel``がリサイズされると?、コマが進んでしまう
- ``setDisabledIcon``
-- 別途用意した静止画像を使って、JLabel#setDisabledIcon(...)を設定
-- ``GrayFilter.createDisabledImage(Image)``でアイコンをグレースケール化
- `Default`
-- デフォルトの`JLabel`では`JLabel#setEnabled(false)`を設定してもアニメーションは停止しない
- `Override imageUpdate(...)`
-- `JLabel#imageUpdate(...)`の`infoflags`から`FRAMEBITS`フラグを落とすことでアニメーションを停止
-- `JLabel`がリサイズされると?コマが進んでしまう
- `setDisabledIcon`
-- 別途用意した静止画像を使って`JLabel#setDisabledIcon(...)`を設定
-- `GrayFilter.createDisabledImage(Image)`でアイコンをグレースケール化

//**参考リンク
**コメント [#k10a32fd]
* 参考リンク [#reference]
- [http://duke.kenai.com/iconSized/index.html Duke Images: iconSized]
- [https://docs.oracle.com/javase/jp/8/docs/api/java/awt/image/ImageObserver.html ImageObserver (Java Platform SE 8)]
- [[ColorConvertOpで画像をグレースケールに変換>Swing/ColorConvertOp]]
- [[Animated Gifからフレーム画像を抽出する>Swing/ExtractFramesFromAnimatedGif]]

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