开发者

Java Look-And-Feel for Tray Messages on Ubuntu

开发者 https://www.devze.com 2023-03-18 17:14 出处:网络
I\'m displaying messages on the system tray via trayIcon.displayMessage(...) but they don\'t look nice.

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.se开发者_如何学JAVAtLookAndFeel(...) 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);


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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号