• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

questions regarding system tray and tray icon

 
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.
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • 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?
 
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
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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]
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic