Skip to content

Instantly share code, notes, and snippets.

@BenjaminEHowe
Created March 26, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminEHowe/85504a45d0173fd940a484e07d8bd694 to your computer and use it in GitHub Desktop.
Save BenjaminEHowe/85504a45d0173fd940a484e07d8bd694 to your computer and use it in GitHub Desktop.
/*
* 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
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment