TITLE:TrayIconのアニメーション
#navi(../)
*TrayIconのアニメーション [#fe9b32a0]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2007-02-05~
更新日:&lastmod;

#contents

**概要 [#s2d078f8]
SystemTrayに追加したアイコン(JDK 6 以上)をア二メーションさせます。

#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;
     }
 });
}}
//-&jnlp;
-&jar;
-&zip;

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

//**参考リンク
**コメント [#x7cedb82]
- animated gif を使うほうが簡単だと思うのですが、作ったGifが悪いのか、環境のせいなのか、残像がでてしまいます。 -- [[terai]] &new{2007-02-05 (月) 19:00:34};

#comment