Make Tray Icon in Java

Hello Friends
I am working on Windows OS. I have made an Application in Java.
I want to crete its icon in the System Tray like comes the icon of various application like SQL Server and of System Clock.
Does Java Support making such icons.
If yes then
Any one who knows please help me.
Its urgent.
with thanks
Vishwajeet

http://www.nevaobject.com/java/jcoro/coroutine4java.htm#example

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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can't get the java tray icon or the console to appear

    I can't get the java tray icon or the console to appear on any system that I've tested my applications in.
    I'm using Windows XP mostly and I've also tested on Windows 2000 and 2003. I'm using jre 1.6. I've already set the icon to appear and the console to show on the advanced tab on the java icon in the control panel. I've even tried another application from another author thinking it might be something in the code of my own application.
    I need the console available on the client systems for troubleshooting but I can't get it to open and I can't open it manually from the tray icon because the icon is not there.
    I seem to remember seeing the tray icon and the console on other systems/applications in the past so what do you think is the problem?

    AFAIK, the Sun/Oracle-provided "Java Console" only works (appears) with applets and Java Web Start applications. It shows some information that is unique to those environments, and provides a place for System.out data to be written.
    For a Java application, if the application is started with the java command (as opposed to the javaw command) System.out data is written to the command/cmd window that is created.
    If you need more that that for an application, then [this article|http://www.developer.com/java/other/article.php/630821/Creating-a-Custom-Java-Console.htm] may be of interest. It's old, but still appears to be valid. Note that current versions of Java contain a class java.io.Console. This class should be able to be used as a replacement for the custom Console class that is used in the article.

  • System Tray Icon Not Displaying - Depending on Launch Style

    Good Morning-
    I'm using the java.awt.SystemTray and TrayIcon classes from 1.6 to create a system tray that acts essentially as a temperature monitor. It's very little code. When I test it from Eclipse, it works great. When I double-click the .jar on my workstation, it works great. When I launch it with java -jar temp.jar, it works great. When I launch it with javaw -jar temp.jar, I get no tray icon, but javaw sits in memory doing something.
    When my users launch it with a .vbs that calls java -jar temp.jar and hides the resulting terminal window, they get no tray icon. When they call java -jar temp.jar, they get the tray icon... and the console window. When they call javaw -jar temp.jar, they get no tray icon. Any of these practices yields a java process sitting in memory.
    When my users double-click the .jar file, they're asked to chose what to open it with. If they chose Java's executable, it says it doesn't know what to do (it isn't called with -jar). Windows doesn't see their jar files as executables like on mine.
    So I have two issues. The result is the system tray icon won't display on users' computers without a window to accompany it. Any idea why? Is it potentially a bug?
    Some code:
    public class SysTrayController {
         // The actual icon that will be updated
         private TrayIcon          icon;
         // The last-set temperature
         private int                    temp;
         // The box that may or may not appear
         private AlertBox          box;
         // No Data received (yet?)
         public final static int NO_DATA = 0;
         // High temperature threshold.  TODO:  Make this user-configurable.
         private final static int     HIGH_TEMP = 80;
         // ... you guess
         private final static String DEFAULT_ICON =  "icons/default.png";
          * Initiate everything.  Grab the system tray, plop the icon in it, and
          * get the icon all set up and ready to go with the default image.
         public SysTrayController() {
              box = new AlertBox();
              SystemTray tray = SystemTray.getSystemTray();
              Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(DEFAULT_ICON));
              PopupMenu popup = new PopupMenu();
              MenuItem exit = new MenuItem("Exit");
              exit.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        System.exit(0);
              popup.add(exit);
              icon = new TrayIcon(image, "Temperature Monitor", popup);
              // On double-click, display the alert box
              icon.addMouseListener(new MouseAdapter() {
                   public void mouseClicked(MouseEvent e) {
                        if (e.getClickCount() >= 2) {
                             box.setVisible(true);
              try {
                   tray.add(icon);
              } catch (AWTException e) {
                   System.out.println(e);
          * Set the temperature.
          * Call setIcon() to set the icon to the right number, update the alert
          * box, and if it's time to, display the alert box.
         public void setTemp(int temp) {
              if (this.temp != temp) {
                   this.temp = temp;
                   setIcon(temp);
                   icon.setToolTip(temp + " degrees");
                   box.setAlertMessage("Temperature in the Server Room is at " + temp + " degrees!");
                   box.setIcon(icon.getImage());
                   if (temp > HIGH_TEMP) {
                        box.setVisible(true);
                        icon.displayMessage("Alert", "Temperature in the server room is at " + temp + " degrees!", TrayIcon.MessageType.WARNING);
                   } else if (temp != NO_DATA){
                        box.setVisible(false);
          * Figure out which icon to set the tray icon to, scale it down, and
          * set it.
         public void setIcon(int number) {
              Image image = null;
              if (number == NO_DATA) {
                   image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(DEFAULT_ICON));
              } else if (number >= 60 && number < 100 ) {
                   String iconString = "icons/temp";
                   iconString += number;
                   iconString += ".png";
                   try {
                        image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(iconString));
                   } catch (NullPointerException e) {
                        image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(DEFAULT_ICON));
              image = image.getScaledInstance(16, 16, Image.SCALE_SMOOTH);
              icon.setImage(image);
          * Give back the current temperature.
         public int getTemp() {
              return temp;
    }The main() that calls it looks like this:
         public static void main(String[] args) {
              SysTrayController controller = new SysTrayController();
              Thermometer temp = new Thermometer(HOSTNAME);
              while (true) {
                   controller.setTemp(temp.getTemp());
                   try {
                        if (controller.getTemp() == SysTrayController.NO_DATA) {
                             Thread.sleep(1000);
                        } else {
                             Thread.sleep(SLEEPTIME);
                   } catch (Exception e) {
                        System.out.println(e);
         }

    From the code above, this line actually worked for me:
    image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(iconString));Just place the image inside the source folder and change the iconString thing...
    For example mine looked like this
    image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icon.gif"));

  • Proper tray icon iconify/bring to front behavior

    Hi, I have a small but annoying problem with JDIC tray icons and JFrame. Maybe there's some really simple solution for this but I can't see it.
    My app has one JFrame and a TrayIcon for it. Currently, a click to tray icon iconifies the frame when it's visible, and a click to tray deiconifies the frame when it's iconified. Simple enough, but my problem comes when I try to make the behavior a little more user-friendly: when the frame is visible, a click to to tray should bring it to the front IF it's not the topmost window - and iconify only when it's the topmost window.
    The problem is, that when I click the tray icon - the JFrame loses it's focus and my code just always brings the frame on top.
    Here's my code (Workbench contains a JFrame):
    tray.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        Workbench workbench = app.getWorkbench();
                        if (workbench.isIconified()) {
                             if (!workbench.isVisible()) {
                                  workbench.setVisible(true);
                             workbench.deiconify();
                             workbench.toFront();
                        } else {
    // here's the problem
                             if (workbench.isFocused()) {
                                  workbench.iconify();
                             } else {
                                  workbench.toFront();
              });I thought about somekind of timer hack, that would check the time since the frame lost focus and compare it to current time when I press the tray icon, but that's an ugly solution - and some users might hold the button down longer than others.
    Another would be to ask the topmost OS window with JNI (afaik. there is no such method in Java?)
    btw. I just tried how mIRC does this, and it seems to get stuck to the "toFront()-state" too, when I set some another window to an "always-on-top"-mode. So I guess it's not the most ideal solution to ask the OS for the topmost window - but that would still do it for me.
    Anyone have other ideas ?
    Message was edited by:
    finalfrontier

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

  • How do I get firefox 3.5 back? Firefox 4 can't find yahoo.mail URL. Using your suggestions has caused me to loose my system tray icons and printers from my computer altogether and my system restore will no longer work either.

    Firefox 4.0 cannot find the Yahoo mail URL. Working with the Verizon tech we were able to get Internet Explorer to finaly find the yahoo mail web site. But not luck with Firefox 4.0 .
    Since trying your suggestions to make firefox 4 find the Yahoo mail URL. I have noticed that all of my system tray icons except the Panda anti virus and volume control icons have disapeared. My system restore will not restore and printers are gone altogether. How do I get the old firefox and all i've lost back.
    Hector, [email protected]

    Still cannot fix it to get Yahoo e-mail. This what I get now from Ff3.5 now.
    Sorry, we can't find "http://us.mc1121.mail.yahoo.com/mc/welcome". Please check the spelling of the web address.
    From Ff4 it can't find the " URL proxy server" on it's server???
    Have tried most every solutions/suggestion I could find have my computer just keeps getting worse. Where do I find the 4 solutions you mention here to see if I have not already tried them? I don't see or know where to go to find these solutions??? Can anyone help me find the fix???
    E-mail add. [email protected]

  • Need to Lock down Keyboard Manager System Tray Icon

    I run 27 MacBooks at a Secondary School. I have them setup for Windows XP Pro (I'll be setting up the Mac OS over then next few weeks but this is a MS Windows School so lets start slow). Hoever I need to be able to disable the "Boot Mac OS" option on the Keyboard Manager. But still have access to Volume and Eject etc Keys.
    Solution: 1
    a .adm file so that I can contol what is avilable to students through Group Policy (disable reboot in Mac, Disable Boot Camp First time Run Help Screen)
    Solution 2
    A Keyboard driver that will make all the Keys work (and remote if possible) but has no System tray Icon
    Solution 3
    Hide the System tray icon (as say an option in the Boot Camp Control Panel which I can already disable through group policy) then all I need to kill is the anoying first time run help screen.
    The help screen is anoying because for each of the 800 student will probably only login into each laptop once each so that will come up every time, because I reimage every 3 months or so.
    The reboot in Mac OS would be no problem if it did not perminatly change to boot order and the Mac OS side boot change back is too complicated for most first time Mac users. The way I will be introducing the Mac OS is telling them about the hold the "option" key trick on boot. hence the dummys will get what they are expecting, and the smarties have the option without afecting the dummys.
    I relise this is a Devolopers thing but I can find no other way to inform them of the need. I dout I am the only System admin needing this.
    Thank You
    Message was edited by: Solus Venator

    Unfortunately no that did not help
    Using msconfig only stops the Keyboard Manager from running. I can do that simply be removing it from the registry with out the annoying msconfig messages. (good for testing though)
    I have also looked into the Hide tray Icon Path but that only tucks it behind a set of “<<”
    And the reboot function does Permanently Change the Boot Order. (Not the boot sector necessarily, The Boot Order) to change it back you need to login into the Mac OS and System Prefs Disk Boot Select the Boot Camp Part and Reboot …… Big Pain in neck.
    The Keyboard Manager icon does not have an eject option… If is needed for the Eject Key to work (and the Volume Mute, Up, Down, Brightness Up, Down. Note it is not Needed for the Play FF Rew Keys they work fine with the Fn Key)
    Here is the test
    With no icon showing, or an icon with no reboot option : Press The Eject Key if the CD Ejects Success, I also need Volume do not care about the others as much
    As Stated this is a Developer( Programmer) oversite and needs them to put in an option to remove the reboot option from the System tray Icon. Removal of the Icon would also be desirable
    Thank You

  • Sometimes Tray Icon not loaded correctly

    I am trying to make my (html/ajax) website available as a desktop application, (with little enhancements like notifications in the background etc.)  without writing any extra code. Everything works fine except the tray icon. Sometimes the tray icon is not loading correctly.
    Following is the structure of my sample air application.
    1. An html page(page1.html) i am using as my inital window.
    It creates an invisible html window and loads a new page (page2.html) as below.
            var options = new air.NativeWindowInitOptions();
            options.systemChrome = "standard";
            var windowBounds = new air.Rectangle(200,250,300,400);
            newHTMLLoader = air.HTMLLoader.createRootWindow(false, options, false, windowBounds);
            newHTMLLoader.window.mainAppWindow = window;
            newHTMLLoader.load(new air.URLRequest("page2.html"));
    and later redirecting to the website.
    2. I am using this invisible html window to control the application behavior (like sending ajax requests in the background, monitoring network, checking for updates etc.)
    page2.html contains code to load the tray icon for the application.
    Here is javascript the code in page2.html
    function BgWindow(){
            this.init = function(){
                this.loadTrayIcon();
            var iconLoadComplete = function(event){
                air.NativeApplication.nativeApplication.icon.bitmaps = [event.target.content.bitmapData];
            this.loadTrayIcon = function() {
                air.NativeApplication.nativeApplication.autoExit = true;
                var iconLoad = new air.Loader();
                if (air.NativeApplication.supportsSystemTrayIcon) {
                    iconLoad.contentLoaderInfo.addEventListener(air.Event.COMPLETE,iconLoadComplete);
                    iconLoad.load(new air.URLRequest("lmt16.png"));
        window.onload = function(){
            bgWindow = new BgWindow();
            bgWindow.init();       
    But the problem here is, sometimes the icon is loaded correctly but sometimes its not loaded.
    What am I missing here ?
    Any help is appreciated.
    I am attaching the complete application if somebody needs to analyze it.

    Sorry. Your attachment didn't come through. It triggered an error message about a "malformed container violation." Please try to rezip it and try it again.

  • Is there any way by which I can not use Thunar Sys Tray icon?

    I am using stalonetray in OpenBox in Arch and when I copy-paste or cut-paste files in Thunar, a sys tray icon pops up. I don't want it to pop up.
    Is there any way by which I can make it to not pop up?

    Trilby wrote:
    I haven't used thunar for a while - but I don't remember it ever doing this before.  I just verified that it doesn't here (freshly installed thunar, and cut-pasted, copy-pasted, etc, and I didn't get a tray icon.
    Are you sure this isn't some other tool, like a clipboard manager?  Are their any tooltip popups or menus available on the tray icon and/or what happens when you click the icon?
    No. I use only Thunar. When I hover on the icon it says that "1 file operation running" when a copy-paste or cut-paste operation happens and when I left click and right click on it, it shows the copying window of thunar. The icon shows two small yellow folders placed diagonally. It's the same icon that appears on the file operation progress window of Thunar. I don't know whether Numix has anything to do with the specific icon though.
    Last edited by chosentorture (2015-01-11 00:13:32)

  • 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

  • Dynadock V system tray icon has vanished

    I have had a Dynadock V since February, 2012. Recently, the system tray icon vanished. Because it's not there, I can't undock to take my laptop somewhere else. I have to shut down the laptop and then I figure it's safe to unplug the dynadock. I've searched for help on the Toshiba website, and all I get is the statement that the icon won't be present unless the computer is connected and a monitor is attached to the dynadock. Well, the computer IS connected and I'm right now watching the monitor connected via the dynadock. But no icon that lets me undock. The users manual clearly says not to disconnect the cable without undocking, and suggests clicking the "show hidden icons button." I've done that, and the icon is not there. Does anybody know what's going on and how to fix it?  Thanks in advance.
    Nancy
    Solved!
    Go to Solution.

    Solution. After messing around with this for way too many hours, I've found a fix. Maybe it can help someone else.
    In Windows Explorer, I found the application that puts the icon in the tray. In my case (Windows 7) it was located at C:/Program Files/TOSHIBA/Dynadock_II/TosDockApp.exe.  Double clicking that put the icon in the tray, but it would be gone the next time I rebooted.
    It needed to be in the Startup folder. I'm guessing that once upon a time it was there and got removed for some unknown reason. (a Windows update?) Right clicked on the application, clicked "Create Shortcut," clicked Yes to placing it on desktop. Then used the Start button, All Programs, and found Startup in the list. Right click, Open. Maneuevered the window so I could see the desktop simultaneously, and dragged the shortcut from the desktop to the list of files on the right side of the Startup window.
    This solution has survived one computer restart, so I'm hoping it will last.
    By the way, copying the application and pasting it in the startup folder didn't work. I had to make the shortcut.
    And Toshiba, if you're listening, I'm still ticked off. Someone in Customer Support should have been able to help me with this. Or it should have been on a troubleshooting page. I've been struggling to find a solution to this problem for months. It wasn't hard -- just not obvious to someone (me) who doesn't work with this software everyday.

  • [Desktop] System Tray Icon: Add back Playback Controls

    I just downloaded the latest version of Spotify with the minimize Spotify to the system tray.  Thank you for that.  You guys are getting there in fufilling my feedback request to keep the system tray icon.  When Spotify minimizes to the tray, it runs in the backround and does not use up alot of CPU just like the Spotify minmize to taskbar option; however, you still need to work on putting the play, pause, next and previous controls back in the system tray icon.  I'm glad the tray icon is back.  It definately makes our computer perform better when we are listening to our Spotify tunes.  Congratulations!  Hope to see this request get put back in the Spotify system tray icon.  Thank you!

    I agree play/pause, next and previous are needed.In addition, option to minimize the program to tray by double-click would be very useful.

  • System tray Icon!!!

    Hi all,
    I have created an application. Now i want that application to be converted to an exe and i also want to post that into the system tray.
    I just need to have an icon in the destop and wen double cliked it has to reach the system tray. On right clicking on the system tray icon i will need a pop window and show certain funcyions like open,etc....
    kindly help me...
    Thanx for reading....

    To generate an executable you need to use an ahead-of-time Java compiler. Here's one: http://gcc.gnu.org/java/. Although that's for *nix you could check whether it's available in cygwin (I'm assuming you need this for Windows). There are some available for windows but I think they're all commercial (i.e., cost money).
    Keep in mind that by doing this you're losing platform independence.
    As for the system tray icon, can't help you there.

  • Beats audio tray Icon

    Hello Community
    I have Notebook with beatsaudio.  Today beatsaudio system tray / taskbar Icon loaded.  When I first setup machine I was able to set so Icon does not populate.  I do not mean I was able to hide Icon.  I did something at machine setup so Icon does not load.    I've looked for beats startup ... nothing jumps out as beats.
    I've been up over and around my machine.  I cannot figure out why Icon is suddenly back nor how to make Icon not load.
    I do not use beatsaudio outside what ever default influence beats has on audio.   I can open beatsaudio control panel....but, cannot find check box not to load tray Icon.    Rt Clk Icon does not have hide option.  Granted I may hide Icon behind ....but, I want Icon not to load. 
    Any ideas.....
    This question was solved.
    View Solution.

    @bjm,
    Hello and thank you for posting on the HP support forums.  First thing you will want to try is to us the Microsoft configuration tool.  
    Using System Configuration (msconfig)
    Besides shutting things down in the startup tab check under the services tab.
    If you can not find this then do a system restore back before you noticed the problem.
    HP PCs - Using Microsoft System Restore (Windows 8)
    Please let me know how things go.
    Thank you again for posting and have a great day.
    Please click the "Thumbs Up" on the bottom right of this post to say thank you if you appreciate the support I provide!
    Also be sure to mark my post as “Accept as Solution" if you feel my post solved your issue, it will help others who face the same challenge find the same solution.
    D5GR
    I work on behalf of HP

Maybe you are looking for