Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

questions regarding system tray and tray icon

 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic