From c61b78a5f5a67c0a3f63274aaa4cf83d62dd74e0 Mon Sep 17 00:00:00 2001 From: litwak913 Date: Sun, 10 Nov 2024 02:17:11 +0800 Subject: [PATCH] fix: tray left space and thread --- core/src/cn/harryh/arkpets/tray/HostTray.java | 16 +++++++++++--- .../cn/harryh/arkpets/tray/MemberTray.java | 22 ++++++++++++++++--- .../harryh/arkpets/tray/MemberTrayImpl.java | 2 ++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/core/src/cn/harryh/arkpets/tray/HostTray.java b/core/src/cn/harryh/arkpets/tray/HostTray.java index 6c8c6cd6..a2922c70 100644 --- a/core/src/cn/harryh/arkpets/tray/HostTray.java +++ b/core/src/cn/harryh/arkpets/tray/HostTray.java @@ -32,9 +32,17 @@ public class HostTray { private static HostTray instance; static { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception ignored) {} + // Avoid AWT Thread problem. + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + if (laf.contains("WindowsLookAndFeel")) { + UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); + UIManager.put("Menu.margin",new Insets(2,-15,2,2)); + } + } catch (Exception ignored) {} + }); Const.FontsConfig.loadFontsToSwing(); } @@ -90,6 +98,8 @@ public void mouseClicked(MouseEvent e) { showStage(); } }); + SwingUtilities.updateComponentTreeUI(popMenu); + popMenu.pack(); } else { Logger.error("HostTray", "Tray is not supported."); } diff --git a/core/src/cn/harryh/arkpets/tray/MemberTray.java b/core/src/cn/harryh/arkpets/tray/MemberTray.java index 7e8de110..d243bb10 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTray.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTray.java @@ -7,6 +7,7 @@ import cn.harryh.arkpets.concurrent.SocketData; import javax.swing.*; +import java.awt.*; import java.util.UUID; @@ -21,9 +22,17 @@ public abstract class MemberTray { protected final String name; static { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (Exception ignored) {} + // Avoid AWT Thread problem. + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + if (laf.contains("WindowsLookAndFeel")) { + UIManager.put("MenuItem.margin",new Insets(2,-15,2,2)); + UIManager.put("Menu.margin",new Insets(2,-15,2,2)); + } + } catch (Exception ignored) {} + }); Const.FontsConfig.loadFontsToSwing(); } @@ -47,6 +56,13 @@ public MemberTray(String name) { optTransparentDis .addActionListener(e -> sendOperation(SocketData.Operation.NO_TRANSPARENT_MODE)); optChangeStage .addActionListener(e -> sendOperation(SocketData.Operation.CHANGE_STAGE)); optExit .addActionListener(e -> sendOperation(SocketData.Operation.LOGOUT)); + + optKeepAnimEn .setIcon(null); + optKeepAnimDis .setIcon(null); + optTransparentEn .setIcon(null); + optTransparentDis .setIcon(null); + optChangeStage .setIcon(null); + optExit .setIcon(null); } abstract public void onExit(); diff --git a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java index 98bb4293..144b8ede 100644 --- a/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java +++ b/core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java @@ -69,6 +69,8 @@ public void firePopupMenuWillBecomeInvisible() { onDisconnected(); client.connectWithRetry(onConnected, session); } + SwingUtilities.updateComponentTreeUI(popMenu); + popMenu.pack(); } private static String getName(ArkPets boundArkPets) {