0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Agent Cosmic
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.