Created
March 26, 2018 12:26
-
-
Save BenjaminEHowe/85504a45d0173fd940a484e07d8bd694 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: https://www.raspberrypi.org/forums/viewtopic.php?f=81&t=209142