Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



How to use the System Tray in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 16-02-2010
- Empty Shell -'s Avatar
Member
 
Join Date: Aug 2006
Posts: 112
How to use the System Tray in Java?

Hello friends,
I want to use the System Tray in my application so that the users can access currently running programs. I have tried to do lot many things but I was not getting the desired output. So thought that some guys over there would be interested in helping me. So please tell me how to use the System Tray in Java? Hope that someone would help me sooner.!!
__________________
As you simplify your life, the laws of the universe will be simpler; solitude will not be solitude, poverty will not be poverty, nor weakness.Henry David Thoreau
Reply With Quote
  #2  
Old 16-02-2010
Viensterrr's Avatar
Member
 
Join Date: Jul 2006
Posts: 232
Re: How to use the System Tray in Java?

The system tray is used so that the user can access the currently running programs. The system tray is a specialized area of the desktop from which the users can access the programs that are running currently. You can see the different area on the various operating system. Like the system tray is referred to as the Taskbar Status Area on the Windows created by Microsoft. The java.awt.SystemTray class of Java represents the system tray for a desktop.
__________________
Signatures reduce available bandwidth
Reply With Quote
  #3  
Old 16-02-2010
Deabelos's Avatar
Member
 
Join Date: Jul 2006
Posts: 233
Re: How to use the System Tray in Java?

You should know that only a single instance created within SystemTray class can exist. I think that providing the methods for that would be helpful. The following are the methods that are used for SystemTray API :
  • add - This method adds a tray icon to the system tray. After adding this the tray will become visible in system tray.
  • getSystemTray - By using this method you will gets the SystemTray instance that represents the desktop's tray area.
  • isSupported - This method returns information as to whether the system tray is supported on the current platform.
__________________
IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....
Reply With Quote
  #4  
Old 16-02-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
Re: How to use the System Tray in Java?

I have given you the sample of coding that can help you for creating the System Tray in Java. The following sample of the coding shows how to add a tray icon to the system tray and apply a pop-up menu :
Code:
...
        if (!SystemTray.isSupported()) {
            System.out.println("SystemTray is not supported");
            return;
        }
        final PopupMenu pop = new PopupMenu();
        final TrayIcon trayIcon =
                new TrayIcon(createImage("picture12.gif", "tray icon"));
        final SystemTray tray = SystemTray.getSystemTray();
       
        MenuItem aboutItem = new MenuItem("Information");
        CheckboxMenuItem cb1 = new CheckboxMenuItem("Set Colors");
        CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
        Menu displayMenu = new Menu("Show");
        MenuItem errorItem = new MenuItem("Error");
        MenuItem warningItem = new MenuItem("Warnings");
        MenuItem infoItem = new MenuItem("Related");
        MenuItem noneItem = new MenuItem("None");
        MenuItem exitItem = new MenuItem("Close");
       
        pop.add(aboutItem);
        pop.addSeparator();
        pop.add(cb1);
        pop.add(cb2);
        pop.addSeparator();
        pop.add(displayMenu);
        displayMenu.add(errorItem);
        displayMenu.add(warningItem);
        displayMenu.add(infoItem);
        displayMenu.add(noneItem);
        pop.add(exitItem);
       
        trayIcon.setPopupMenu(pop);
       
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.out.println("TrayIcon could not be added.");
        }
...
Reply With Quote
  #5  
Old 16-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: How to use the System Tray in Java?

You should also know about the TrayIcon object while writing the coding of the System Tray. A TrayIcon object can be described as a tray icon that can be added to the system tray. Also going in little bit deep description a TrayIcon object can have a tooltip, an image, a pop-up menu, and a set of listeners associated with it. The methods for TrayIcon API are as follows :
  • setImageAutoSize - This method sets the auto-size property. You should keep in mind that by default, the auto-size property is set to false.
  • setPopupMenu - This method sets the pop-up menu for this TrayIcon object.
  • setToolTip - This method sets the tooltip string for this TrayIcon object.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use the System Tray in Java?"
Thread Thread Starter Forum Replies Last Post
System slow down with gray bitdefender system tray icon Jigya L. Networking & Security 4 18-02-2011 07:40 PM
Java - System Tray with timer Anthony12 Software Development 4 20-07-2010 12:58 PM
Icons in system tray myz14 Customize Desktop 3 22-05-2010 05:27 AM
Minimizing to System Tray John Windows Vista Mail 14 12-04-2010 05:33 AM
System Tray Icons MyD0j0 Windows XP Support 8 11-05-2007 07:59 AM


All times are GMT +5.5. The time now is 03:54 AM.