我有以下代码来创建具有PopupMenu的TrayIcon:
public void addToTray()
{
try
{
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
PopupMenu popMenu= new PopupMenu();
MenuItem exititem = new MenuItem("Exit");
popMenu.add(exititem);
BufferedImage trayImg = ImageIO.read(new File("Geqo.png"));
ImageIcon ii = new ImageIcon(trayImg);
TrayIcon trayIcon = new TrayIcon(ii.getImage(), "Geqo", popMenu);
trayIcon.setImageAutoSize(true);
SystemTray.getSystemTray().add(trayIcon);
}
catch (Exception e)
{
e.printStackTrace();
}
}
这段代码旨在创建一个带有弹出菜单的系统托盘图标。它可以正常工作,但我不喜欢默认的LAF(我认为是Metal)。因此,我尝试将LAF更改为Nimbus,以及操作系统默认设置Windows,但没有成功。LAF似乎没有变化。有谁能指导我如何更改LAF吗? 提前感谢您 :)!!