Swing/AnimatedTrayIcon のバックアップの現在との差分(No.3)
TITLE:TrayIconのアニメーション
TrayIconのアニメーション
編集者:Terai Atsuhiro~
作成日:2007-02-05
更新日:2024-04-12 (金) 14:50:28
概要
SystemTray
に追加したトレイアイコンをアニメーションさせます。
Screenshot
Advertisement
概要
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