Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1022
  • Last Modified:

BufferedImage on JButton

I'm outa points so I don't hold out much hope of anyone replying but,

I have loaded a jpg into a BufferedImage and converted to an ImageIcon and stuck it on a JButton either in the JButton constructor or using setIcon(...)

Is there an easy way to make the BufferedImage 50% transparent or change it to grayscale or anything (I want the button to gray out or faded colour.

1 Solution
You can use AlphaComposite.

Draw a Rectangle over the button, and then keep calling repaint, each time updating the AlphaComposite value, which will allow you to paint a white rectangle and gradually make it more and more transparent, this will make it look like the button is fading in :)

This is how to do it!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now