Set up a system tray for a software

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.