问题
I'm displaying messages on the system tray via trayIcon.displayMessage(...) but they don't look nice. I tried to change their look and feel to the system standard, but calling UIManager.setLookAndFeel(...) before creating the icon didn't change anything.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
tray = SystemTray.getSystemTray();
popup = new PopupMenu();
trayIcon = new TrayIcon(image, "Tray Demo", popup);
tray.add(trayIcon);
trayIcon.displayMessage("Tray Test", "Tray demo started", TrayIcon.MessageType.INFO);
回答1:
Here you can find a great tutorial how to get rid of awt and use swing. Then you can have every look and feel you want.
The only problem is that the popup menu does not disappear if you click outside of it. The quickest workaround can be adding a menu item (named Dispose or whatever you want) which does nothing but you can click on it and the menu disappears :)
回答2:
You should change the look and feel before you start your application or else make some extra method calls to cause Swing to redraw the widgets. See http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html for more.
来源:https://stackoverflow.com/questions/6600638/java-look-and-feel-for-tray-messages-on-ubuntu