| Author |
Display String in System Tray (instead of TrayIcon)
|
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
thank you very much Rob, it worked perfectly....
|
 |
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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
Joined: Apr 22, 2006
Posts: 16
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
You can use the code I provided loooong ago and use the Graphic2D object's drawImage methods.
|
 |
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
Are you sure those resources are right? Because that code should work.
What does the following print:
|
 |
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
file:/Users/jonathanculloty/forge/BBUM/bin/bbum/img/leftside.gif
file:/Users/jonathanculloty/forge/BBUM/bin/bbum/img/rightside.gif
|
 |
Jonathan Culloty
Greenhorn
Joined: Apr 22, 2006
Posts: 16
|
|
Fiund this, it seems to be the same problem....
http://forums.sun.com/thread.jspa?threadID=736202
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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
Joined: Apr 22, 2006
Posts: 16
|
|
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
Joined: Jun 13, 2009
Posts: 1786
|
|
|
Just thought I'd mention the Compound Icon which may be easier then doing your own custom painting.
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8430
|
|
Cool!
I can see from the figure that overlay/merge is also possible.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
That CompoundIcon looks pretty cool, but it's not really appropriate here. TrayIcon takes an Image, not an Icon.
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1786
|
|
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.
|
 |
 |
|
|
subject: Display String in System Tray (instead of TrayIcon)
|
|
|