Reputation: 25
I've created a calculator using AWT Frames. I wanna know how to add a tray-icon to my Cal. I can only use AWT not Swing.
Upvotes: 2
Views: 790
Reputation: 21004
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().createImage("pathToImage"));
final SystemTray tray = SystemTray.getSystemTray();
try {
tray.add(trayIcon);
} catch (AWTException e) {
System.out.println("TrayIcon could not be added.");
}
Found at this page http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html
You should also check if SystemTray
is supported before using the following snippet
if (!SystemTray.isSupported()) {
System.out.println("SystemTray is not supported");
//..
}
Note that SystemTray
is from package java.awt
as per your request.
Upvotes: 2