Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jeans.trayicon
Class WindowsTrayIcon

    java.lang.Object
      com.jeans.trayicon.WindowsTrayIcon

public class WindowsTrayIcon
extends java.lang.Object

WindowsTrayIcon A Java Implementation for showing icons in the Windows System Tray Written by Jan Struyf (jan.struyf@cs.kuleuven.ac.be) (http://ace.ulyssis.org/~jeans) Instantiate this class for each icon This file comes with native code in TRAYICON.DLL The DLL should go in C:/WINDOWS/SYSTEM or in your current directory

Field Summary
`static int` | `BALLOON_ERROR`
`static int` | `BALLOON_INFO`
`static int` | `BALLOON_NONE`
`static int` | `BALLOON_NOSOUND`
`static int` | `BALLOON_WARNING`
`static int` | `DLLNOTFOUND`
`static int` | `ERRTHREAD`
`static int` | `JNIERR`
`static int` | `METHODID`
`static int` | `NOERR`
`static int` | `NOLISTENER`
`static int` | `NOTENOUGHMEM`
`static int` | `NOTIFYPROCERR`
`static int` | `NOVMS`
`static int` | `TOOMANYICONS`
`static java.lang.String` | `TRAY_VERSION`
`static int` | `WIN_VER_2K`
`static int` | `WIN_VER_95`
`static int` | `WIN_VER_98`
`static int` | `WIN_VER_ME`
`static int` | `WIN_VER_NET`
`static int` | `WIN_VER_NT`
`static int` | `WIN_VER_UNKNOWN`
`static int` | `WIN_VER_WIN32`
`static int` | `WIN_VER_XP`
`static int` | `WRONGICONID`

Constructor Summary
`WindowsTrayIcon(java.awt.Image image, int w, int h)` Construct a new Tray Icon Using a Java Image - This can be loaded from a 16x16 GIF or JPG file Param image 16x16 icon - make sure it's loaded in memory - use MediaTracker Param w the icon width - eg.

Method Summary
`void` | `addActionListener(java.awt.event.ActionListener listener)` Add an ActionLister to this icon Just like with java.awt.Button or javax.swing.JButton Param listener = your listener
`void` | `addMouseListener(java.awt.event.MouseListener listener)`
`static void` | `cleanUp()` Free all native resources - call this method before System.exit()
`void` | `freeIcon()` Free all native resources for this icon On exit use cleanUp()
`static java.awt.Window` | `getCurrentWindow()`
`static TrayDummyComponent` | `getDummyComponent()`
`static int` | `getLastError()` Return error code from native library - use for debugging
`static int` | `getWindowsVersion()`
`static java.lang.String` | `getWindowsVersionString()`
`static void` | `initHook()`
`static void` | `initJAWT()`
`static void` | `initTrayIcon(java.lang.String appName)` Init native library - call this method in the main() method of your app Param appName = the title for the hidden window Each app has it's own hidden window that receives the mouse/menu messages for it's Tray Icons The window title is used by sendWindowsMessage() and isRunning() to identify an app
`static boolean` | `isRunning(java.lang.String appName)` Checks if there's an instance with hidden window title = appName running Can be used to detect that another instance of your app is already running (so exit..) Param appName = the title of the hidden window to search for
`boolean` | `isVisible()` Test if this icon is currently visible in the Windows System Tray Returns true if visible
`static void` | `keepAlive()` Keep TrayIcon alive (make sure application does not exit)
`void` | `removeActionListener(java.awt.event.ActionListener listener)`
`void` | `removeMouseListener(java.awt.event.MouseListener listener)`
`static int` | `sendWindowsMessage(java.lang.String appName, int message)` Send a message to another app (message can contain an integer) Can be used to detect that another instance of your app is already running That instance can for example restore it's window after it receives the windows message - see demo app for more info Param appName = the title of the hidden window to search for Param message = the integer message to send (only native int size supported)
`static void` | `setAlwaysOnTop(java.awt.Component wnd, boolean onTop)`
`static void` | `setCurrentWindow(java.awt.Window wnd)`
`void` | `setImage(java.awt.Image image, int w, int h)` Change this icon's Image Using a Java Image - This can be loaded from a 16x16 GIF or JPG file Param image 16x16 icon - make sure it's loaded in memory - use MediaTracker Param w the icon width Param h the icon height Exception TrayIconException - if something goes wrong :O( - Error loading icon image Exception InterruptedException - if the thread loading the image is interrupted
`static void` | `setMouseClickHook(java.awt.event.MouseListener listener)`
`static void` | `setMouseHookEnabled(int enable)`
`void` | `setPopup(TrayIconPopup popup)` Set new popup menu The popup menu is displayed when the user right clicks the icon See class TrayIconPopup, TrayIconPopupSimpleItem, ..
`void` | `setToolTipText(java.lang.String tip)` Changes the text for the ToolTip of this icon The ToolTip is displayed when the user mouses over the icon Param tip = the new text for the ToolTip
`void` | `setVisible(boolean status)` Show/Hide this icon in the Windows System Tray Param status true = show, false = hide
`static void` | `setWindowsMessageCallback(TrayIconCallback callback)` Set callback method for receiving windows messages See sendWindowsMessage() for more information or take a look at the demo app Param callback = the callback method for this app
`void` | `showBalloon(java.lang.String msg, java.lang.String title, int timeout, int flags)`
`static boolean` | `supportsBallonInfo()`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### TRAY_VERSION

    public static final java.lang.String TRAY_VERSION

See Also:
  Constant Field Values

### BALLOON_NONE

    public static final int BALLOON_NONE

See Also:
  Constant Field Values

### BALLOON_INFO

    public static final int BALLOON_INFO

See Also:
  Constant Field Values

### BALLOON_WARNING

    public static final int BALLOON_WARNING

See Also:
  Constant Field Values

### BALLOON_ERROR

    public static final int BALLOON_ERROR

See Also:
  Constant Field Values

### BALLOON_NOSOUND

    public static final int BALLOON_NOSOUND

See Also:
  Constant Field Values

### NOERR

    public static final int NOERR

See Also:
  Constant Field Values

### NOTIFYPROCERR

    public static final int NOTIFYPROCERR

See Also:
  Constant Field Values

### TOOMANYICONS

    public static final int TOOMANYICONS

See Also:
  Constant Field Values

### NOTENOUGHMEM

    public static final int NOTENOUGHMEM

See Also:
  Constant Field Values

### WRONGICONID

    public static final int WRONGICONID

See Also:
  Constant Field Values

### DLLNOTFOUND

    public static final int DLLNOTFOUND

See Also:
  Constant Field Values

### NOVMS

    public static final int NOVMS

See Also:
  Constant Field Values

### ERRTHREAD

    public static final int ERRTHREAD

See Also:
  Constant Field Values

### METHODID

    public static final int METHODID

See Also:
  Constant Field Values

### NOLISTENER

    public static final int NOLISTENER

See Also:
  Constant Field Values

### JNIERR

    public static final int JNIERR

See Also:
  Constant Field Values

### WIN_VER_UNKNOWN

    public static final int WIN_VER_UNKNOWN

See Also:
  Constant Field Values

### WIN_VER_WIN32

    public static final int WIN_VER_WIN32

See Also:
  Constant Field Values

### WIN_VER_95

    public static final int WIN_VER_95

See Also:
  Constant Field Values

### WIN_VER_98

    public static final int WIN_VER_98

See Also:
  Constant Field Values

### WIN_VER_ME

    public static final int WIN_VER_ME

See Also:
  Constant Field Values

### WIN_VER_NT

    public static final int WIN_VER_NT

See Also:
  Constant Field Values

### WIN_VER_2K

    public static final int WIN_VER_2K

See Also:
  Constant Field Values

### WIN_VER_XP

    public static final int WIN_VER_XP

See Also:
  Constant Field Values

### WIN_VER_NET

    public static final int WIN_VER_NET

See Also:
  Constant Field Values

Constructor Detail

### WindowsTrayIcon

    public WindowsTrayIcon(java.awt.Image image,
                           int w,
                           int h)
                    throws TrayIconException,
                           java.lang.InterruptedException

  Construct a new Tray Icon Using a Java Image - This can be loaded from a 16x16 GIF or JPG file Param image 16x16 icon - make sure it's loaded in memory - use MediaTracker Param w the icon width - eg. 16 Param h the icon height - eg. 16 Exception TrayIconException - if something goes wrong :O( - Too many icons allocated - Error initializing native code DLL - Error setting up Windows notify procedure - Error loading icon image Exception InterruptedException - if the thread loading the image is interrupted

Method Detail

### initTrayIcon

    public static void initTrayIcon(java.lang.String appName)

  Init native library - call this method in the main() method of your app Param appName = the title for the hidden window Each app has it's own hidden window that receives the mouse/menu messages for it's Tray Icons The window title is used by sendWindowsMessage() and isRunning() to identify an app

### cleanUp

    public static void cleanUp()

  Free all native resources - call this method before System.exit()

### setImage

    public void setImage(java.awt.Image image,
                         int w,
                         int h)
                  throws TrayIconException,
                         java.lang.InterruptedException

  Change this icon's Image Using a Java Image - This can be loaded from a 16x16 GIF or JPG file Param image 16x16 icon - make sure it's loaded in memory - use MediaTracker Param w the icon width Param h the icon height Exception TrayIconException - if something goes wrong :O( - Error loading icon image Exception InterruptedException - if the thread loading the image is interrupted

  Throws:
    `TrayIconException`
    `java.lang.InterruptedException`

### setVisible

    public void setVisible(boolean status)

  Show/Hide this icon in the Windows System Tray Param status true = show, false = hide

### isVisible

    public boolean isVisible()

  Test if this icon is currently visible in the Windows System Tray Returns true if visible

### setToolTipText

    public void setToolTipText(java.lang.String tip)

  Changes the text for the ToolTip of this icon The ToolTip is displayed when the user mouses over the icon Param tip = the new text for the ToolTip

### showBalloon

    public void showBalloon(java.lang.String msg,
                            java.lang.String title,
                            int timeout,
                            int flags)

### addActionListener

    public void addActionListener(java.awt.event.ActionListener listener)

  Add an ActionLister to this icon Just like with java.awt.Button or javax.swing.JButton Param listener = your listener

### removeActionListener

    public void removeActionListener(java.awt.event.ActionListener listener)

### addMouseListener

    public void addMouseListener(java.awt.event.MouseListener listener)

### removeMouseListener

    public void removeMouseListener(java.awt.event.MouseListener listener)

### setPopup

    public void setPopup(TrayIconPopup popup)

  Set new popup menu The popup menu is displayed when the user right clicks the icon See class TrayIconPopup, TrayIconPopupSimpleItem, .. Param popup = the popup menu

### freeIcon

    public void freeIcon()

  Free all native resources for this icon On exit use cleanUp()

### setAlwaysOnTop

    public static void setAlwaysOnTop(java.awt.Component wnd,
                                      boolean onTop)

### getLastError

    public static int getLastError()

  Return error code from native library - use for debugging

### isRunning

    public static boolean isRunning(java.lang.String appName)

  Checks if there's an instance with hidden window title = appName running Can be used to detect that another instance of your app is already running (so exit..) Param appName = the title of the hidden window to search for

### sendWindowsMessage

    public static int sendWindowsMessage(java.lang.String appName,
                                         int message)

  Send a message to another app (message can contain an integer) Can be used to detect that another instance of your app is already running That instance can for example restore it's window after it receives the windows message - see demo app for more info Param appName = the title of the hidden window to search for Param message = the integer message to send (only native int size supported)

### setWindowsMessageCallback

    public static void setWindowsMessageCallback(TrayIconCallback callback)

  Set callback method for receiving windows messages See sendWindowsMessage() for more information or take a look at the demo app Param callback = the callback method for this app

### keepAlive

    public static void keepAlive()

  Keep TrayIcon alive (make sure application does not exit)

### setCurrentWindow

    public static void setCurrentWindow(java.awt.Window wnd)

### getWindowsVersionString

    public static java.lang.String getWindowsVersionString()

### getWindowsVersion

    public static int getWindowsVersion()

### supportsBallonInfo

    public static boolean supportsBallonInfo()

### getDummyComponent

    public static TrayDummyComponent getDummyComponent()

### initJAWT

    public static void initJAWT()

### initHook

    public static void initHook()

### setMouseHookEnabled

    public static void setMouseHookEnabled(int enable)

### setMouseClickHook

    public static void setMouseClickHook(java.awt.event.MouseListener listener)

### getCurrentWindow

    public static java.awt.Window getCurrentWindow()

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD