Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Copyright Benjamin Howe 2018
* This code is released under the CC0 license
* See:
package uk.bh96;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
public class SystemTrayMinimal {
public static void main(String[] args) throws AWTException, IOException {
// create the graphic for the tray icon
BufferedImage trayIconImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphic = trayIconImage.createGraphics();
graphic.clearRect(0, 0, 256, 256);
// resize the tray icon
SystemTray tray = SystemTray.getSystemTray();
int trayIconWidth = tray.getTrayIconSize().width;
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
System.out.println("The tray icon was resized to " + trayIconWidth + "px wide.");
// add the tray icon to the tray
// wait for input, then die;

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.