I'm developing a software for my final project. I need to disable other buttons when user clicked on the correct answer. But the problem is that after disabling buttons it changed to gray. But I need to keep them without change.
Asked
Active
Viewed 1,777 times
-1

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
Please don't deface your question either. – Hovercraft Full Of Eels Aug 20 '16 at 01:56
-
Also you'll want to post your code, including your btnCorrectBeeActionPerformed method as code-formatted text, not as an image. – Hovercraft Full Of Eels Aug 20 '16 at 01:57
-
xD you sent a screen shot of your code – whyn0t Aug 20 '16 at 04:34
1 Answers
5
Simply wire their ActionListeners not to respond when you desire the button to be turned off. A simple boolean field would suffice, say private boolean buttonsOff
Check the state of the field in the ActionListener and when true, exit the listener immediately.
Other options:
- remove the ActionListeners from the button when you desire them to not function
- Swap the button with a JLabel if you want to remove their "clickability", something that can be done with CardLayout.
- Make the disabled icon the same as the default icon.

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
2+1d for the technical side, but I would argue that a disabled button which looks like a normal button is confusing for the user. A grey button is probably the most universal way of making it obvious. I would have seen *Don't do it* as a reasonible answer as well – Dici Aug 19 '16 at 23:22
-
@Dici: I agree. Best would be to somehow indicate to the user in a standard fashion, that the button is no longer active. – Hovercraft Full Of Eels Aug 19 '16 at 23:23
-
I changed the buttons color to red when user clicked on the wrong answer. I need to keep this change after user clicked on the right answer. but when user clicked on the right answer other buttons are disabled and that color effect was lost. can you tell me a way to do it – Aug 19 '16 at 23:27
-
@Priya: yes I can tell you. Please read the answer above. If you have any specific questions about the potential solutions, please ask. If you have any code questions, please post code (in your question, not in a link). – Hovercraft Full Of Eels Aug 19 '16 at 23:31
-
Yep. I know this is not the standard. but i just need to do it. bcz i need to get a screenshot of this page automatically when user going to the next page. Without previous color changes I can't understand mistakes of the user by using screenshots. pls help me. this is my final project – Aug 19 '16 at 23:35
-
I'll remove this comment later but @user6736712 www.youtube.com/watch?v=XmlXU4uK5rA . if you expect help then you have to explain the problem properly, to get the right answer =]. we don't even know how your program is structured – whyn0t Aug 20 '16 at 04:53