BufferedImage on JButton

Posted on 2004-11-27
Last Modified: 2012-05-05
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.

Question by:KOTOR
    1 Comment
    LVL 2

    Accepted 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

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now