System tray functionality in java

Hi friends,
I wanted to know which is the best package to use for implementing the system tray functionality in java.
I read about systray, jtray,trayicon etc. I saw that TrayIcon is included in jdk 1.6. Is there any other included package in swing which will do this?
i am just a beginner in swing programming.
Thanks in advance.

i would say not. as far as i can remember you can't directly set icons on a AWT MenuItem.
and you shouldn't mix awt and swing components and most of the time can't do it anyway.
however, if you have your own MenuItem i recon you could overwrite paint and paint the icons,
i.e. images yourself using graphics2D methods.
if you want to dig deeper into it, there are some good tutorials on paint:
[http://java.sun.com/products/jfc/tsc/articles/painting/]
might be worth, if you really want to have images and icons on your menuitems.
i have never done this myself for awt components, but it should work.
just found something interesting though:
[http://atunes.svn.sourceforge.net/viewvc/atunes/aTunes_HEAD/src/net/sourceforge/atunes/gui/views/controls/JTrayIcon.java?view=markup]
apparently, using this class, which derives from the normal TrayIcon, you can set a JPopupMenu and therefore use normal swing components.
i did not try it though, but it looks very promising.
Edited by: produggt on 20.08.2008 22:08

Similar Messages

  • Getting System tray icons in Java

    I have developed a swing application and want to control the number of instances running of my own Java class. Is there a simple way how I can do the task?
    Also, i am putting my application in the System tray so, can i get a list of icon for all applications in the system tray? (may be i can control multiple instance using this simple technique)

    sandeep_khurana wrote:
    kevinaworkman wrote:
    Didn't you even look at the API?
    http://java.sun.com/javase/6/docs/api/java/awt/SystemTray.html
    actually the problem is that it is giving null because the api says that it will give the details for the icons by
    'this' application. what i want is all the icons, then, i will decide whether to launch or exit in the succeeding instances of my class.Are you saying that you want to see all of the "icons" in the system tray so that you can iterate over them to see if your icon is one of them and - if it is - not launch your application?
    You're not going to want to do it that way. The "how do I ensure that my program launches only once" problem has been discussed on these forums many times.
    Some options include:
    bind a socket to a not-often-used-port such as 9999 or 9998 or something like that. Two sockets cannot bind to the same port, so that would let you know that you're already running.
    Check for the existence of a file. When you launch your application, if the file exists, it's already running. Delete the file when your program terminates. This technique is pretty common on *NIX systems.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Popup Menu in system tray - Linux OS -- JAVA 1.4.2

    Hi,
    I have made an app in Linux( centOS 4.6) which need to pop a message up on system tray when a certain number is reached. I know there is the way to do in sdk1.6. The question: Is there any workaround for 1.4.2 because the deployment machine is in 1.4.2 and the customers dont want to switch to 1.6.
    Some hints, links or keywords are appreciated.
    Thank you

    Have a look at JDIC. (Note: I haven't used that yet, and I don't know which jdk it requires.)

  • J2SE 6 and System tray ideas

    Guys .i'm a bit confused about few issues
    1) whether
    J2SE6 = Mustang ?
    2) Does either one of these support
    java.awt.SystemTray
    coz im looking 4 an API in java tht supports System tray functionality...
    3) And i also saw tht "jdic" also supports system tray... So which of these should i use.. any suggestions ? or should i use a 3rd party API
    if so wht ?
    Help would be greatly appreciated as this is for my final project in my Degree ...
    thx

    Guys .i'm a bit confused about few issues
    1) whether
    J2SE6 = Mustang ?they are the same
    ) Does either one of these support
    java.awt.SystemTrayyes, Java 6 supports this.
    3) And i also saw tht "jdic" also supports system
    tray... So which of these should i use.. anyif you can not use java 6, yes.
    suggestions ? or should i use a 3rd party APIjdic is 3rd party.

  • Restoring a JFrame from system Tray

    Hi,
    I am writing a small application to see new system tray api in java.
    Currentlty i am facing a problem - My application minimizes to system tray correctly but when i restore it by clicking on to the tray icon it remains in the minimize state but i want it in restore state.
    private void initTrayIcon()
                Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");
                PopupMenu popup = new PopupMenu();
                MenuItem defaultItem = new MenuItem("Exit");
                defaultItem.addActionListener(new ActionListener()
                    public void actionPerformed(ActionEvent e)
                        exitApplication();
                popup.add(defaultItem);
                trayIcon = new TrayIcon(image, "Tray Demo", popup);
                trayIcon.setImageAutoSize(true);
                trayIcon.addMouseListener(new MouseAdapter()
                    public void mouseClicked(MouseEvent e)
                        //System.out.println("Tray Icon - Mouse clicked!");                
                        setVisible(true);
        }Code of constructor
    initTrayIcon()     
         addWindowListener(new WindowAdapter()
                public void windowDeiconified(WindowEvent e)
                        if (SystemTray.isSupported())
                            SystemTray tray = SystemTray.getSystemTray();
                            tray.remove(trayIcon);
                            setVisible(true);
                            requestFocus();
                public void windowIconified(WindowEvent e)
                    try
                        if (SystemTray.isSupported())
                            SystemTray tray = SystemTray.getSystemTray();
                            tray.add(trayIcon);
                            //setExtendedState(ICONIFIED);
                            setVisible(false);
                    catch (AWTException ex)
                        System.err.println("TrayIcon could not be added.");
            });

    Here is complete code for those who are still facing this problem.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SystemTrayFinalExample extends JFrame
         public SystemTrayFinalExample()
              if(!SystemTray.isSupported())
                   JOptionPane.showMessageDialog(this,"Your system doesn't supports System Tray","ERROR",0);
                   System.exit(0);
              initComponents();
         private void initComponents()
              setTitle("System Tray Demo");
              setSize(300,200);
              popupmenu = new PopupMenu();
              menuitem1 = new MenuItem("Exit");
              menuitem1.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent exx)
                        System.exit(0);
              popupmenu.add(menuitem1);
              trayicon = new TrayIcon(Toolkit.getDefaultToolkit().getImage("computer.png"),"System Tray Final Example",popupmenu);
              trayicon.addMouseListener(new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                                    if(e.getButton() == MouseEvent.BUTTON1)
                                            setVisible(true);
                                            setExtendedState(JFrame.NORMAL);
              addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                        System.exit(0);
                   public void windowIconified(WindowEvent ex)
                        setVisible(false);
                        try
                             SystemTray.getSystemTray().add(trayicon);
                        catch(AWTException e)
                             e.printStackTrace();
                        trayicon.displayMessage("Message","Click this icon to restore window",TrayIcon.MessageType.INFO);
                   public void windowDeiconified(WindowEvent ex)
                        SystemTray.getSystemTray().remove(trayicon);
         public static void main(String args[])
              new SystemTrayFinalExample().setVisible(true);
         private TrayIcon trayicon;
         private PopupMenu popupmenu;
         private MenuItem menuitem1;
    }

  • Attaching window system tray icon events to java frame

    I need to bring java frame to front on an event with the icon placed in the system tray. Like if I click the mouse on it.. the frame should come to front.
    Any body who can help, I will really appreciate.
    Thanks in advance
    Zeeshan

    I am very interested in implementing just such a thing with my Java application. I am in the starting phases of this project and ran across your post in my search for info.
    How much do you already have implemented? I.E., can you display the icon but are just having trouble catching the events for when the icon is clicked? Or do you not even have the ability to display the icon yet? I have found the Windows documentation on the MSDN site for the shell function Shell_NotifyIcon(), which is what we want to use but I have not begun any attempts to use it yet.
    If you (or anyone else) have any info or have had any success at all with this yet, I would be very interested in hearing how it works. I'll be happy to share any info I find, when/if I get that far.
    Thanks,
    j

  • How to put a Java Program into the System tray

    Hi all of the forum!!
    I have a question. I want to make a monitor program but I don't know how to put the program in the system tray or just to execute the program but automatically (no manual execute), but i dont want that the program appear in a window, just start to function when i start my PC. i hope anybody help me.
    Thanks
    Best Regards
    Bucio, Francisco

    There is a plenty of similar topics here, so you can use the Search on this forum or in Google to find out.
    But shortly, you will need to use JNI or get a ready-to-use library like JNIWrapper (http://www.jniwrapper.com/winpack.jsp#tray), for example, that lets you do what you want.
    Good luck,
    EToporov

  • How to put Java application in the MS. Windows System tray

    dear all,
    Is it possible to make a Java application communicate with the MS. Explorer and to put a Java application in the MS. Windows System tray
    Regards

    http://www.esus.com/docs/GetQuestionPage.jsp?uid=624
    or look for madcap on sourceforge

  • Move Java Frame into Windows taskbar notification area (system tray)?

    Hi,
    I was wondering if anyone has written a service-like application in Java running (and appearing) in the Windows "taskbar notification area", instead of running in the convential Windows taskbar.
    I'm able to add an icon to the taskbar notification area (frequently errorneous called as the 'system tray') by using some native code that uses win32 Shell_NotifyIcon(.. , ..). However, I'm not able to 'couple' the window (i.e. the Java frame) to the new icon in the taskbar.
    My icon is shown in the area AND the frame is shown as an application in the taskbar... I would like to 'remove' my Java application from the taskbar and place it 'as an icon' in the taskbar notification area.
    Has anyone had experience with a similar problem?
    Many thanks!
    Jasper

    If all you need is to make the frame not visible in the taskbar as well than why don't you activate the hide() method? cature the minimize event and activate the frame.hide(); method. And in the system tray make the frame visible by frame.show();

  • How to minimize ie to system tray using java

    click ie minimize button and show an icon in system tray area not in task bar
    and then click the icon to restore the ie window.
    help me about this,thank you very much!

    Use JNI.
    I have seen the code posted on this forum before on how to do this, I think by me. Also the example on using JNI ("99% Java" article) does this.
    So STFF.

  • Java System Tray Menu- pop up on left click.

    Hi,
    The system tray menu will normally pop up on mouse right click. I need to make this pop up on mouse left click. Is it possible? I had tried a lot and failed to find a solution. Please help me on this issue.
    Thank You.

    Hi,
    Thank you for your answer,
    I had tried a lot to make pop up the system tray menu on mouse left click. Finally i got a way to do this. My code is,
    MouseListener ml;
            ml = new MouseListener() {
                public void mouseClicked(MouseEvent e) {
                    if (mouseflag == 0) {
                        try {
                            Robot robot = new Robot();
                            // RIGHT CLICK
                            robot.mousePress(InputEvent.BUTTON3_MASK);
                            robot.mouseRelease(InputEvent.BUTTON3_MASK);
                        } catch (Exception exe) {
                            System.out.println("error=" + exe);
                        mouseflag = 1;
                    } else {
                        mouseflag = 0;
            public void mouseEntered(MouseEvent e) {
              System.out.println("Tray icon: Mouse entered");
            public void mouseExited(MouseEvent e) {
              System.out.println("Tray icon: Mouse exited");
            public void mousePressed(MouseEvent e) {
              System.out.println("Tray icon: Mouse pressed");
            public void mouseReleased(MouseEvent e) {
              System.out.println("Tray icon: Mouse released");
          };here i had created a mouse right click using code (robot class) on mouse clicked. Now i can pop up menu on left click. But now my issue is, i am not able to remove right click functionality. I think this is in built function for system tray menu. please help or give suggestions on this issue. I think that the way which i used to pop up menu on left click is not a good one. If i removed right click then this code may not work.
    Thank you,
    Sreejith P.M.
    Edited by: Sreeksd on Jan 6, 2011 11:39 PM

  • Java System Tray Menu

    Hi,
    I am able to use a png icon in my system tray element. ( TrayIcon trayIcon =new TrayIcon(createImage("/images/e-vision3.png", "tray icon"));) . Now i need to add icons to some MenuItems. ie, Both menu name and an icon. I had tried a lot to make this working but failed. Please help me on this issue.
    Thankyou.
    Sreejith P.M.

    Hi,
    Thank you for your answer,
    I am not using JMenuItem. in my application i had used awt MenuItem. (ie, used MenuItem aboutItem = new MenuItem("About"); not JMenuItem aboutItem = new JMenuItem("About"); ) We can add trat icon to system tray. when mouse right click the menu and menu items will show. I need to add some icons in the pop up menu items. Can i do this?
    Thankyou,
    Sreejith
    Edited by: user13423634 on Dec 29, 2010 10:34 PM

  • How to add a minimize to system tray icon button?

    how can i add a minimize to system tray icon button near the others common buttons usually found on the upper right window bar? (i mean near the _ [] X)
    _ for minimize to taskbar
    [] for maximizing
    X for closing
    i'd like to add a fourth button to the left of the _ button for minimizing to system tray
    like in many programs the fourth button is a dot shaped one that minimizes the program to system tray
    i'd like to add one to my program as well, but i didnt find anything about this kind of buttons neither on google nor on java books
    can anyone help me?
    thank you!

    You can't (easily). The window decorations are controled by the operating system. Your best bet is to change the functionality of the minimize-to-taskbar button and make it into a minimize-to-tray button. In fact, all the programs that minimize to the tray on my computer - about 6 of them - do it this way.
    like in many programs the fourth button is a dot shaped one that minimizes the program to system trayI've never seen this?

  • System tray notification

    Hi all,
    Is it possible to generate an alert which appears above the system tray icon, similar to how MSN messenger or Gmail Notifier alerts the user of new emails (a small popup appears for a few seconds, then vanishes)?
    If so, please give me some link or source code ....
    My jre version is 1.4.2._06
    Thank you
    Ismail sheikh

    armalcolm wrote:
    BalusC wrote:
    So, you want to generate platform specific behaviour? Java is supposed to be platform independent. Either use JNI to access platform specific libraries, or use another language which has natively access to platform specific libraries. In case of Windows that is at least C++.Hardly platform specific. Windows, Linux and Mac have a system tray and notifications of some sort.You're right about the platform support, but behind the scenes it is still platform specific.
    Which is presumably why Java now supports this functionality.The topistarter is using JDK 1.4.2. We can of course advise him to upgrade to JDK 6.0.
    Topicstarter: check this article: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/

  • System Tray notification icon erratically appearin...

    Sometimes, but not consistently, when I boot my Windows 7 Pro desktop, Skype (v7.1.0.105) appears in my system tray as a tiny green icon with a yellow checkmark. When someone IMs me, it shows a notification on that icon, and I can click on it to respond. Other times, also at boot, while it does show up in Task Manager, there is nothing in the system tray, and I have no way to ping someone else unless I click on the main Skype icon on the desktop to bring up the interface, where it takes up space on my taskbar. X'ing out closes it, although I know it's running because I can see it in the Task Manager but if someone want to ping me, I'm not sure if they can even see me unless I click on the desktop icon to load it. When I do that, it stays in my task bar, but I still can't see it in the system tray, despite having it set to show icon and notifications. Looking at that now, the config states I'm not signed in, but I am!
    1) Why do I see that system tray icon sporadically? I'd prefer it be there all the time.
    2) Even when it does show up, it is VERY easy to overlook, because it's so tiny that I frequently overlook it until hours later. Is there any way to make it do a pop-up instead?
    What am I doing wrong? I only use Skype for simple IM.
    TIA
    Elaine
    Ivy, VA

    armalcolm wrote:
    BalusC wrote:
    So, you want to generate platform specific behaviour? Java is supposed to be platform independent. Either use JNI to access platform specific libraries, or use another language which has natively access to platform specific libraries. In case of Windows that is at least C++.Hardly platform specific. Windows, Linux and Mac have a system tray and notifications of some sort.You're right about the platform support, but behind the scenes it is still platform specific.
    Which is presumably why Java now supports this functionality.The topistarter is using JDK 1.4.2. We can of course advise him to upgrade to JDK 6.0.
    Topicstarter: check this article: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/

Maybe you are looking for

  • How do I use Lightning Camera Kit and charge iPad at the same time?

    Well, that's the question. I don't like interrupting my creative work only to charge this device, I'd like to have a charger and any other external device working at the same time. If you know such product which has Lighning feed-through with a charg

  • Dynamic change in the query name based on user input

    Hi Gurus, In a scenario, country appears as a user input variable.When the user specifies his country, the same query displays <b>Business trends</b>' data pertaining to his own country and rest of the world(international) in two tables.The reports a

  • Join Paths

    Let me select multiple paths, and where the endpoints occupy the same position (or within a user-definable distance), choose Object > Join Paths. I work with DWG site plans within Illustrator frequently. When these files are imported, complex paths a

  • Host command in oracle forms

    can anyone any one help me on this issue i am trying to use host command in a.s which is running in unix o.s to rename one of the file i am using the below command but its not working . can any one tell me whats worng or how to perform this the_comma

  • RFBIBL00 - File format

    Hi all, I would like to use standard program RFBIBL00 to perform journal postings. I have read a lot of documentation and discussions on it. However one thing I could not find is what the file format should be i.e. fixed length, coma-delimited, tab d