Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized tray menu lookandfeel #85

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading