概要

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

サンプルコード

TrayIcon icon = new TrayIcon(imglist[0], "TRAY", popup);
animator = new Timer(100, new ActionListener() {
  private int idx = 0;
  @Override public void actionPerformed(ActionEvent e) {
    icon.setImage(imglist[idx]);
    idx = (idx + 1) % imglist.length;
  }
});
View in GitHub: Java, Kotlin

解説

上記のサンプルでは、16x16の画像を3パターン用意しこれをJDK 6で追加されたTrayIcon#setImage(Image)メソッドを使って切り替えることでトレイアイコンのアニメーションを行っています。

参考リンク

コメント