I'm making a Java Application on Linux that uses sytray using Java 6 and Swing. The app looks great (uses the system look and feel) but the systray looks awful. I mean the systray menu looks like old widgedts (Motif?). I wonder if there is a way to set a look and feel or something to make the system tray prettier.
Heres a screenshot of the tray:
Have you tried JXTrayIcon?
I tested this demo from SwingHelper on Ubuntu 10.10 with Compiz and it looks cool.
UPDATE
As 2020, these links are broken and this solution has many drawbacks today. For instance, GNOME3 desktop environments had removed entirely system tray icons and they replaced it with AppIndicator.
Java's (AWT/Swing) System Tray support is broken today. I recommend using this Java library: https://github.com/dorkbox/SystemTray
From the site:
Professional, cross-platform SystemTray support for Swing/AWT, GtkStatusIcon, and AppIndicator on Java 6+. This library provides OS Native menus and Swing/AWT menus, depending on the OS and Desktop Environment and if AutoDetect (the default) is enabled.
For reference, you can found a copy of the original example at here
Swing uses emulated UI widgets. It has a number of styles or themes you can apply. If you would prefer more native results you will need to look for another widget toolkit. You have a few options:
If your needs are very basic, you may be happy with AWT that is the original Java UI toolkit. It uses native widgets, but has very limited library of widgets that it supports.
If you want to go beyond AWT, consider SWT, which is maintained at eclipse.org. It gives you a rich library of widgets, that are implemented natively.
Because Swing use AWT on Systray, if you want great looking on systray. Maybe you can try with SWT :)
I wrote my own library for it. Here is the link:
http://www.2shared.com/file/sQdjb6aG/jtray.html
Usage:
import javax.swing.jtray.*;
JTrayIcon.initSystemTray();
JTrayIcon icon = new JTrayIcon(img, "Tooltip", jpopupmenu);
icon.displayMessage(null, "Title", "Multiline\nsecondline", 3000); // 3 seconds
The library uses a few dirty tricks, so maybe it may not work on any Linux platform as good as in Ubuntu. It should work for Windows and OSX as well.
I haven't tried it myself, but if you're using Java 6 Update 10 or later, can you use the new Nimbus look and feel?:
Using Nimbus LAF
I've heard of tray icons using "JPopupMenu" on Ubuntu, which uses the Nimbus look and feel, so this may be your best bet:
Using JPopupMenu in TrayIcon
From what I've seen, using JPopupMenu alone would be a big improvement - coupled with Nimbus it should be awesome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With