License Public Domain
Lines 38
Keywords
java (9) system tray (1)
Permissions
Owner: monkey103
Viewable by Everyone
Editable by All Siafoo Users
Hide
Siafoo is here to make coding less frustrating and to save you time. Join Siafoo Now or Learn More

System tray icon in Java Atom Feed 0

# 's
 1//Check the SystemTray support
2if (!SystemTray.isSupported()) {
3 System.out.println("SystemTray is not supported");
4 return;
5}
6final PopupMenu popup = new PopupMenu();
7final TrayIcon trayIcon =
8 new TrayIcon(createImage("images/bulb.gif", "tray icon"));
9final SystemTray tray = SystemTray.getSystemTray();
10
11// Create a popup menu components
12MenuItem aboutItem = new MenuItem("About");
13CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
14CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
15Menu displayMenu = new Menu("Display");
16MenuItem errorItem = new MenuItem("Error");
17MenuItem warningItem = new MenuItem("Warning");
18MenuItem infoItem = new MenuItem("Info");
19MenuItem noneItem = new MenuItem("None");
20MenuItem exitItem = new MenuItem("Exit");
21
22//Add components to popup menu
23popup.add(aboutItem);
24popup.addSeparator();
25popup.add(cb1);
26popup.add(cb2);
27popup.addSeparator();
28popup.add(displayMenu);
29displayMenu.add(errorItem);
30displayMenu.add(warningItem);
31displayMenu.add(infoItem);
32displayMenu.add(noneItem);
33popup.add(exitItem);
34
35trayIcon.setPopupMenu(popup);
36
37try {
38 tray.add(trayIcon);
39} catch (AWTException e) {
40 System.out.println("TrayIcon could not be added.");
41 return;
42}