4

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.

ThatGuy343
  • 2,354
  • 3
  • 30
  • 55

1 Answers1

7

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);
Trevi Awater
  • 2,387
  • 2
  • 31
  • 53