From cee7d05e2419f291b0423af69ad104b452329078 Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Sat, 11 May 2024 23:18:34 +0200 Subject: [PATCH] Tray Icon: try to select the icon image with the correct size - otherwise scale the largest one accordingly --- .../java/de/bwravencl/controllerbuddy/gui/Main.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java index fb45ffe2..a6927d14 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java +++ b/src/main/java/de/bwravencl/controllerbuddy/gui/Main.java @@ -2119,7 +2119,18 @@ private void onControllersChanged(final List presentControllers, quitMenuItem.addActionListener(quitAction); popupMenu.add(quitMenuItem); - trayIcon = new TrayIcon(frame.getIconImage()); + final var trayIconSize = systemTray.getTrayIconSize(); + final var trayIconImage = frame.getIconImages().stream() + .filter(iconImage -> iconImage.getWidth(null) == trayIconSize.width + && iconImage.getWidth(null) == trayIconSize.height) + .findFirst() + .orElse(frame.getIconImages().stream() + .max(Comparator + .comparingInt(iconImage -> iconImage.getWidth(null) * iconImage.getHeight(null))) + .orElseThrow() + .getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH)); + + trayIcon = new TrayIcon(trayIconImage); trayIcon.addActionListener(showAction); trayIcon.setPopupMenu(popupMenu); try {