• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display String in System Tray (instead of TrayIcon)

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm using the Java SystemTray http://java.sun.com/javase/6/docs/api/java/awt/SystemTray.html to display a parameter.
I want to read this parameter hourly and display the value in the system tray.
My problem is that I can only display a trayicon and not a string.
I know I can add a popup to the tray icon which contains a string but i wanted the user to see teh string without any interaction.

any ideas how to get around this?
Thanks,

Jonathan
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if the task bar allows icons to be wider than 16 pixels, but you could always create a BufferedImage on which you draw your string:
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much Rob, it worked perfectly....

 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One last quick one, I am currently only able to display 2 characters in the icon using this method.
Is there anyway to squeeze more chars in here, or am I limited to just two?
I guess the 16x16 pixel size of the icon limits the space...
Thanks,
Jon
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can think of two ways to shrink your letters:
1) make a larger image, and call setImageAutoSize(true) on your TrayIcon
2) use a smaller font for the Graphics object.

You can do 2 like this:


Overall 1) should be easier since the size doesn't really matter. You can make the image any size (as long as it is a square), and let the system handle the resize. However, I don't know if it performs well. You will have to test that.
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One last question about Images. I have 2 gifs, both are 8 pixels wide and 16 pixels high.
I want to put one gif on the left side of a system tray icon and the other on the right side.
Sort of like below, is this possible to do? I've been try to get it to work without success for the last while.

Thanks,
Jon

ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
ooooooooxxxxxxxx
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the code I provided loooong ago and use the Graphic2D object's drawImage methods.
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob, I was trying like that except I either saw a completely clear or completely black icon depending on the BufferedImage .TYPE I use... Thanks


 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure those resources are right? Because that code should work.

What does the following print:
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
file:/Users/jonathanculloty/forge/BBUM/bin/bbum/img/leftside.gif
file:/Users/jonathanculloty/forge/BBUM/bin/bbum/img/rightside.gif
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fiund this, it seems to be the same problem....
http://forums.sun.com/thread.jspa?threadID=736202
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ImageIcon calls a protected method called loadImage after it has loaded the image using Toolkit.getDefaultToolkit().getImage:
tracker is an instance of MediaTracker, getNextID() simply returns a new ID each time it's called.
 
Jonathan Culloty
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob, I got it to work, finally.
IconImage was the way to go.
Thanks for your help and patience.
/Jon


 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just thought I'd mention the Compound Icon which may be easier then doing your own custom painting.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool!
I can see from the figure that overlay/merge is also possible.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That CompoundIcon looks pretty cool, but it's not really appropriate here. TrayIcon takes an Image, not an Icon.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:That CompoundIcon looks pretty cool, but it's not really appropriate here. TrayIcon takes an Image, not an Icon.



Oops, good point, I've never used the TrayIcon and was just going by the name.
 
All of the following truths are shameless lies. But what about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic