TITLE:TrayIconのアニメーション
#navi(../)
RIGHT:Posted by [[terai]] at 2007-02-05
*TrayIconのアニメーション [#fe9b32a0]
SystemTrayに追加したアイコン(JDK 6 以上)をア二メーションさせます。

//-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#l1766e4f]
#code{{
final TrayIcon icon = new TrayIcon(imglist[0], "TRAY", popup);
animator = new javax.swing.Timer(100, new ActionListener() {
  private int idx = 0;
  public void actionPerformed(ActionEvent e) {
    icon.setImage(imglist[idx]);
    idx = (idx<imglist.length-1)?idx+1:0;
  }
});
}}

**解説 [#s4dc164c]
16*16の画像を3パターン用意し、これを JDK 6 で追加されたTrayIcon#setImage(Image)メソッドを使って切り替えることでアニメーションしています。

**参考リンク [#af1e3679]
-[[SystemTrayにアイコンを表示>Swing/SystemTray]]
-[[TrayIconのダブルクリック>Swing/ClickTrayIcon]]

**コメント [#x7cedb82]
- animated gif を使うほうが簡単だと思うのですが、作ったGifが悪いのか、環境のせいなのか、残像がでてしまいます。 -- [[terai]] &new{2007-02-05 (月) 19:00:34};
-- メモ: [http://bugs.sun.com/view_bug.do?bug_id=6453582 Bug ID: 6453582 Animation gif too fast] -- [[terai]] &new{2007-04-19 (木) 21:11:50};
-- 上のバグ?でウェイトが効かずに残像が残っていたのではなく、前のコマがそのまま残して透過色(背景色)でクリアしないタイプ?のアニメGIFになっていたようです。[http://homepage3.nifty.com/furumizo/giamd.htm Giam]を使って、全コマの消去方法を「背景色で塗りつぶす」に変更したファイルを使用すると、正常に描画されるようになりました。 -- [[terai]] &new{2007-04-19 (木) 22:04:52};

#comment