public static void main(String[] args) throws AWTException {
final var tray = SystemTray.getSystemTray();
final var blackIcon = new ImageIcon(ResourceUtils.get("/tray/images/recording-dark.png")).getImage();
final var whiteIcon = new ImageIcon(ResourceUtils.get("/tray/images/recording.png")).getImage();
final var popUpMenu = new PopupMenu();
popUpMenu.add("Hello World");
final var trayIcon = new TrayIcon(
MacOSTrayIconFixer.getInitialIcon(blackIcon, whiteIcon),
"Tray Icon Test",
popUpMenu
);
tray.add(trayIcon);
MacOSTrayIconFixer.fix(trayIcon, blackIcon, whiteIcon);
final var pausedBlackIcon = new ImageIcon(ResourceUtils.get("/tray/images/paused-dark.png")).getImage();
final var pausedWhiteIcon = new ImageIcon(ResourceUtils.get("/tray/images/paused.png")).getImage();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
SwingUtilities.invokeLater(()->{
trayIcon.setImage(MacOSTrayIconFixer.getInitialIcon(pausedBlackIcon, pausedWhiteIcon));
});
}
}, 5000);
}
With the code above, the icon image does not get changed after 5000ms.
If I comment out the MacOSTrayIconFixer.fix(trayIcon, blackIcon, whiteIcon);, the switching if icon image works just fine.
Am I just missing something?
I also tried to calling MacOSTrayIconFixer.fix again but it is not working too. It somehow has empty icon graphic but still alive in the menu bar.
OS Version: MacOS 11.5.2
Machine: Mac Mini (2018)
Architecture: Intel Chipset
Sample Code:
With the code above, the icon image does not get changed after 5000ms. If I comment out the
MacOSTrayIconFixer.fix(trayIcon, blackIcon, whiteIcon);
, the switching if icon image works just fine.Am I just missing something?
I also tried to calling
MacOSTrayIconFixer.fix
again but it is not working too. It somehow has empty icon graphic but still alive in the menu bar.OS Version: MacOS 11.5.2 Machine: Mac Mini (2018) Architecture: Intel Chipset