GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes How can i change the Color of Images on JComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can i change the Color of Images on JComponent" Watch "How can i change the Color of Images on JComponent" New topic
Author

How can i change the Color of Images on JComponent

Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
How do i change the color of Image on my JComponent.I placing an Image on JComponent through setIcon() method and passing ImageICon object.How can i change the color of the image which i passed to this Image Object.Or please sussest me any better way of doiing it.
I will be knowing the colors only at runTime.
here is my code which will explain easy to understand...
Say ...
JLabel label=new JLabel("My text");
ImageIcon icon=new IMageIcon("myImage.gif");
label.setIcon(icon);
now how can i change the color of this image in runtime.


Sun Certified Java Programmer
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
Why do you want to change the color? Normally an images has more than one color. Do you want to replace blue by red or something else? Anyway, you should write a bit more.
If you want to do something with images, then probably Java Advanced Imaging would be a good solution.
Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
Originally posted by Rene Liebmann:
Why do you want to change the color? Normally an images has more than one color. Do you want to replace blue by red or something else? Anyway, you should write a bit more.
If you want to do something with images, then probably Java Advanced Imaging would be a good solution.

i want to change the color of image based on user requirements.The original image color may be anything which i am least bothered about.
thanks in advance.
G Estes
Ranch Hand

Joined: Oct 22, 2002
Posts: 62
If your image comes from a gif file, then you can't change it dynamically unless you load a different gif. What I think you may be getting at is changing the appearance of an image based on a given condition or state. If this is the case, then make the gif image have a transparent background. Place the gif into an image and change the image background to what is needed. For instance, have an image of a computer with a green background for available, yellow for in use and red for not operating. All you have to do is call image.setBackground(Color.xxx).
Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
Originally posted by Gil Estes:
If your image comes from a gif file, then you can't change it dynamically unless you load a different gif. What I think you may be getting at is changing the appearance of an image based on a given condition or state. If this is the case, then make the gif image have a transparent background. Place the gif into an image and change the image background to what is needed. For instance, have an image of a computer with a green background for available, yellow for in use and red for not operating. All you have to do is call image.setBackground(Color.xxx).

you guessed right!but i didn't get clear picture
what kind of image object i need to place on the component at the first place.because i am not seeing any methods like setbackground() on Images.
do u mean..

JLabel label =new JLabel();
label.setICon("myICon.gif");
label.setOpaque(true);
label.setBackground(myColorObj);
thanks for u r reply..
Bhagya Tangutur
Ranch Hand

Joined: Oct 21, 2002
Posts: 88
I didn't know that i can make the image transaprent.by changing image to transparent and setting background,it works fine.
Thanks
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"kumar" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
GeeCON Prague 2014
 
subject: How can i change the Color of Images on JComponent