• 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

How can i change the Color of Images on JComponent

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't know that i can make the image transaprent.by changing image to transparent and setting background,it works fine.
Thanks
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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!
 
Destiny's powerful hand has made the bed of my future. And 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