JLabelに表示したAnimated Gifのアニメーションを停止する
Total: 5604, Today: 1, Yesterday: 0
Posted by aterai at
Last-modified:
Summary
JLabelに表示したAnimated GIFのアニメーションを停止します。
Screenshot

Advertisement
Source Code Examples
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, KotlinDescription
上記のサンプルでは、JLabel#isEnabled()がfalseの場合はsetIcon()メソッドで設定したAnimated Gifのアニメーションを停止するなどのテストを行っています。
Default- デフォルトの
JLabelではJLabel#setEnabled(false)を設定してもアニメーションは停止しない
- デフォルトの
Override imageUpdate(...)JLabel#imageUpdate(...)のinfoflagsからFRAMEBITSフラグを落とすことでアニメーションを停止JLabelがリサイズされると?コマが進んでしまう
setDisabledIcon- 別途用意した静止画像を使って
JLabel#setDisabledIcon(...)を設定 GrayFilter.createDisabledImage(Image)でアイコンをグレースケール化
- 別途用意した静止画像を使って
Reference
- Duke Images: iconSized
- ImageObserver (Java Platform SE 8)
- ColorConvertOpで画像をグレースケールに変換
- Animated Gifからフレーム画像を抽出する