I'll make it short.
First is how do I change the text colour of a disabled button. I've tried HTML and setForeground but doesn't work.
Second, when I want to click a button, I can't move my cursor or the event will not fire. I used addMouseListener because I also need to handle a right click.
Third how do I add an icon to the button when I click it.

Thanks.

I have never tried what you want to do but a quick look at the API will get you what you want.
Have you tried looking at the API of the JButton class. If you look at the constructor there is one that accepts an Icon. If you search the page for a setIcon method you will find the class: AbstractButton. JButton extends that class and has access to all of its methods.
If you look at its API you will find several setIcon methods that your JButton instance can call.
Also you will find a setUI method.

Do a little digging and tell us what you have found.

Here's the solution I found. Instead of using setText, I used a label so the colour wouldn't change.
Second, instead of using the mouseClicked event, I used the mouseReleased event so it would still fire.
Well third is using setIcon.

But here's the problem. Is it possible for the icon not to change colour when the button is disabled, it becomes light gray.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.