Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System tray text instead of icon

Tags:

java

swing

awt

How can I display text in the system tray instead of an icon? I want to display a percentage for example.

final TrayIcon trayIcon = new TrayIcon(createImage("image.png", "tray icon"));

The code above is to set an icon, but how can I set text such as 100% to display in the system tray? This is specifically on OSX.

like image 549
ThatGuy343 Avatar asked Mar 17 '23 01:03

ThatGuy343


1 Answers

You can draw the text onto an image, this does the job although you are still using an image. I don't think there is an other way to do it.

BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = image.createGraphics();
g2d.drawString("100%", x, y);
g2d.dispose();
trayIcon.setImage(image);
like image 81
Trevi Awater Avatar answered Mar 28 '23 23:03

Trevi Awater