File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes questions regarding system tray and tray icon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "questions regarding system tray and tray icon" Watch "questions regarding system tray and tray icon" New topic
Author

questions regarding system tray and tray icon

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
hi there. i am developing a chat app... i wanted to add the feature of the messengers like YM that if it closes, it goes to the system tray...
i got this piece of code...



its from a post of mr. Rob Prime... i slightly understand what this is for. all i want to know is how to put the frame on the tray... :O
hope you guys help.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10372
    
    8

More on using the system tray here
http://java.sun.com/docs/books/tutorial/uiswing/misc/systemtray.html

I have reason to believe Mr. Rob Prime will be around today.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
Maneesh Godbole wrote:More on using the system tray here
http://java.sun.com/docs/books/tutorial/uiswing/misc/systemtray.html

I have reason to believe Mr. Rob Prime will be around today.


thanks Mr. Maneesh. i got myself on these codes...



i can see the icon on the system tray already. i set the setDefaultCloseOperation to DO_NOTHING_ON_CLOSE. but everytime i hit the [X] on the title bar, my app would still close and terminate.
did i do something wrong on the code?
Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
if you are using Java 1.6 you can use SystemTray class and put a TrayIcon class in it.
like this:


On your JFrame, add a Class of type WindowAdapter and provide appropriate actions when user closes the Application window(usually you will want to hide the JFrame)

sample window adapter


Then on the JFrame you may do something like this.


Hope this sample helps!
Ryan Webb


frustrated to learn c/c++/objective-c
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Maneesh Godbole wrote:I have reason to believe Mr. Rob Prime will be around today.

I guess you're right

Ryan is showing you the right way to minimize to tray. The minimization occurs all by itself but unless you hide the frame as well it will still be visible in the task bar. The reverse is first showing the frame again, then removing the minimized state as you already know how to.

Jhedzkie, are you sure your application is really terminating? Does the tray icon disappear as well? Is the java.exe or javaw.exe still visible in the Windows Task Manager?
I've tried your test code for the JFrame only (so not the tray icon), and if I click [X] it minimizes and restores immediately after. Are you sure the frame has no other window listeners attached to it? If another window listener causes the application to be closed then that one is executed first.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
Rob Prime wrote:
Maneesh Godbole wrote:I have reason to believe Mr. Rob Prime will be around today.

I guess you're right

Ryan is showing you the right way to minimize to tray. The minimization occurs all by itself but unless you hide the frame as well it will still be visible in the task bar. The reverse is first showing the frame again, then removing the minimized state as you already know how to.

Jhedzkie, are you sure your application is really terminating? Does the tray icon disappear as well? Is the java.exe or javaw.exe still visible in the Windows Task Manager?
I've tried your test code for the JFrame only (so not the tray icon), and if I click [X] it minimizes and restores immediately after. Are you sure the frame has no other window listeners attached to it? If another window listener causes the application to be closed then that one is executed first.


yes it is. O_O
that is the only window listener that is present on the frame.
i am using net beans 6.7..

the output pane below says,

BUILD SUCCESSFUL (total time: 4 second)

right after i clicked the [X] button. the system tray icon is showing flawlessly. the only problem is that it closes when i hit [X]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions regarding system tray and tray icon