Results 1 to 5 of 5

Thread: How to use the System Tray in Java?

  1. #1
    Join Date
    Aug 2006
    Posts
    122

    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

  2. #2
    Join Date
    Jul 2006
    Posts
    289

    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

  3. #3
    Join Date
    Jul 2006
    Posts
    286

    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....

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    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.");
            }
    ...

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    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.

Similar Threads

  1. System slow down with gray bitdefender system tray icon
    By Jigya L. in forum Networking & Security
    Replies: 4
    Last Post: 18-02-2011, 07:40 PM
  2. Java - System Tray with timer
    By Anthony12 in forum Software Development
    Replies: 4
    Last Post: 20-07-2010, 11:58 AM
  3. Icons in system tray
    By myz14 in forum Customize Desktop
    Replies: 3
    Last Post: 22-05-2010, 04:27 AM
  4. Minimizing to System Tray
    By Rising in forum Windows Vista Mail
    Replies: 2
    Last Post: 12-04-2010, 04:33 AM
  5. Run Outlook from system tray
    By Clemens in forum Customize Desktop
    Replies: 6
    Last Post: 15-01-2009, 11:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,504,421.52669 seconds with 16 queries