概要
JLabel
に表示したAnimated GIF
のアニメーションを停止します。
サンプルコード
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 all解説
上記のサンプルでは、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からフレーム画像を抽出する