Skip to content

Commit

Permalink
fix: tray left space and thread
Browse files Browse the repository at this point in the history
  • Loading branch information
litwak913 committed Nov 9, 2024
1 parent e320593 commit c61b78a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
16 changes: 13 additions & 3 deletions core/src/cn/harryh/arkpets/tray/HostTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -90,6 +98,8 @@ public void mouseClicked(MouseEvent e) {
showStage();
}
});
SwingUtilities.updateComponentTreeUI(popMenu);
popMenu.pack();
} else {
Logger.error("HostTray", "Tray is not supported.");
}
Expand Down
22 changes: 19 additions & 3 deletions core/src/cn/harryh/arkpets/tray/MemberTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.harryh.arkpets.concurrent.SocketData;

import javax.swing.*;
import java.awt.*;
import java.util.UUID;


Expand All @@ -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();
}

Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions core/src/cn/harryh/arkpets/tray/MemberTrayImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public void firePopupMenuWillBecomeInvisible() {
onDisconnected();
client.connectWithRetry(onConnected, session);
}
SwingUtilities.updateComponentTreeUI(popMenu);
popMenu.pack();
}

private static String getName(ArkPets boundArkPets) {
Expand Down

0 comments on commit c61b78a

Please sign in to comment.