Skip to content

Commit

Permalink
Merge pull request #85 from litwak913/traylaf
Browse files Browse the repository at this point in the history
Optimized tray menu lookandfeel
  • Loading branch information
isHarryh authored Nov 21, 2024
2 parents dd231c9 + 6467fda commit 7cf086e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/src/cn/harryh/arkpets/tray/HostTray.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public class HostTray {
private static HostTray instance;

static {
// Avoid AWT Thread problem.
SwingUtilities.invokeLater(() -> {
try {
String laf = 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));
}
UIManager.setLookAndFeel(laf);
} catch (Exception ignored) {}
});
Const.FontsConfig.loadFontsToSwing();
}

Expand Down Expand Up @@ -87,6 +98,8 @@ public void mouseClicked(MouseEvent e) {
showStage();
}
});
SwingUtilities.updateComponentTreeUI(popMenu);
popMenu.pack();
} else {
Logger.error("HostTray", "Tray is not supported.");
}
Expand Down
17 changes: 17 additions & 0 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,6 +22,15 @@ public abstract class MemberTray {
protected final String name;

static {
// Avoid AWT Thread problem.
try {
String laf = 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));
}
UIManager.setLookAndFeel(laf);
} catch (Exception ignored) {}
Const.FontsConfig.loadFontsToSwing();
}

Expand All @@ -44,6 +54,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

0 comments on commit 7cf086e

Please sign in to comment.