Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Copyright Benjamin Howe 2018
* This code is released under the CC0 license
* See: https://creativecommons.org/publicdomain/zero/1.0/
*/
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;
import java.io.IOException;
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.setBackground(Color.RED);
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
tray.add(trayIcon);
// wait for input, then die
System.in.read();
System.exit(0);
}
}
@BenjaminEHowe

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.