File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display String in System Tray (instead of TrayIcon)

 
Jonathan Culloty
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much Rob, it worked perfectly....

 
Jonathan Culloty
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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


 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just thought I'd mention the Compound Icon which may be easier then doing your own custom painting.
 
Maneesh Godbole
Saloon Keeper
Posts: 10967
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool!
I can see from the figure that overlay/merge is also possible.
 
Rob Spoor
Sheriff
Pie
Posts: 20368
43
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic