These two days just do the exercise, encountered a small software to make the use of the tray, so the part is recorded in handy
(Box body inheritance jframe)
PopupMenu popup = new PopupMenu ();//define popup Menu
Defining Systemtray member variables
Systemtray tray;
Defining TRAYICON member variables
TrayIcon TrayIcon;
Determine if the current operating system supports the system tray
if (systemtray.issupported ())
{
Get the system Tray
Tray = Systemtray.getsystemtray ();
Loading images
Image image = Toolkit.getdefaulttoolkit (). GetImage ("Img/icon.gif");
Create a TrayIcon object to get the system tray
TrayIcon = new TrayIcon (image, "hint message", popup);
Set the system tray icon to set the dimensions automatically
Trayicon.setimageautosize (TRUE);
Try
{
Set the tray icon in the system tray
Tray.add (TrayIcon);
}
catch (Exception e)
{
E.printstacktrace ();
}
Registering listeners for the tray icon
Trayicon.addactionlistener (this);
}
public void actionperformed (ActionEvent e)
{
if (E.getsource==trayicon) {
Double-click the tray icon to execute the code
Display the form in its original way
This.show (TRUE);
}
}
Set up a system tray for a software