Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the java systray look prettier in Linux

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: enter image description here

like image 849
Marcos Roriz Junior Avatar asked Jan 25 '11 02:01

Marcos Roriz Junior


5 Answers

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

like image 97
gorlok Avatar answered Nov 06 '22 16:11

gorlok


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:

  1. 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.

  2. 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.

like image 27
Konstantin Komissarchik Avatar answered Nov 06 '22 17:11

Konstantin Komissarchik


Because Swing use AWT on Systray, if you want great looking on systray. Maybe you can try with SWT :)

like image 2
martinusadyh Avatar answered Nov 06 '22 16:11

martinusadyh


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.

like image 2
Martijn Courteaux Avatar answered Nov 06 '22 18:11

Martijn Courteaux


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.

like image 1
Michael Avatar answered Nov 06 '22 16:11

Michael