Java Look-And-Feel for Tray Messages on Ubuntu

人走茶凉 提交于 2019-12-24 04:07:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!