TITLE:TrayIconのアニメーション

TrayIconのアニメーション

編集者:Terai Atsuhiro~

作成日:2007-02-05
更新日:2024-04-12 (金) 14:50:28
  • category: swing folder: AnimatedTrayIcon title: TrayIconのアニメーション tags: [SystemTray, Icon, Animation] author: aterai pubdate: 2007-02-05T02:07:43+09:00 description: SystemTrayに追加したトレイアイコンをアニメーションさせます。 image: https://lh5.googleusercontent.com/_9Z4BYR88imo/TQTHtWabBgI/AAAAAAAAARk/J0ExgthCnn4/s800/AnimatedTrayIcon.png

概要

SystemTrayに追加したトレイアイコンをアニメーションさせます。

概要

SystemTrayに追加したアイコン(JDK 6 以上)をア二メーションさせます。

#screenshot

サンプルコード

#spanend
 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;
     }
 });
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
TrayIcon icon = new TrayIcon(imglist[0], "TRAY", popup);
#spanend
#spanadd
animator = new Timer(100, new ActionListener() {
#spanend
  private int idx = 0;
  @Override public void actionPerformed(ActionEvent e) {
    icon.setImage(imglist[idx]);
    idx = (idx + 1) % imglist.length;
  }
#spanadd
});
#spanend
  • &jar;
  • &zip;

解説

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

解説

  • 16x16の画像を3パターン用意
  • JDK 6で追加されたTrayIcon#setImage(Image)メソッドを使用して、この3パターンの画像を切り替えることでトレイアイコンのアニメーションを実行

コメント

  • animated gif を使うほうが簡単だと思うのですが、作ったGifが悪いのか、環境のせいなのか、残像がでてしまいます。 -- terai

参考リンク

コメント