This content has been marked as final. Show 7 replies
981556 wrote:Yes, that's the intended behavior...
My action listener is able to perform these basic tasks.... but I can't figure out how to get the action event to fire while the JCheckBox is in the disabled state. That is to say, when the JCheckBox is disabled, clicking on it does not fire my ActionListener.
Maybe you should statr with an MVC-design now.
Then you could manipulate the model rather than the (disabled) ChekckBox and you'd attach your Listener to the backing Model instead of the (disabled) CheckBox...
I can't figure out how to get the action event to fire while the JCheckBox is in the disabled state. That is to say, when the JCheckBox is disabled, clicking on it does not fire my ActionListener.Of course not. There is no event. Nothing happened. Nothing to fire. It's disabled. You disabled it.
How do I override this and fire the ActionListener? Custom Action?You don't. Your question embodies a contradiction in terms. If you want the checkbox to be active and fire events, don't disable it. If you disable it, it won't fire events.
If you want a click that can re-enable it, it will have to be on another component. It is not customary for users to be able to disable and re-enable UI elements. What are you doing exactly?
Thanks for the responses.
I want to avoid having 21 sets of triple radio buttons (Currently have 21 checkboxes) as my UI doesn't have the real estate for this. And it would be overwhelming to look at.
The checkboxes are used for inclusion criteria to narrow down data based on 21 boolean fields. I don't actually want to disable the checkboxes, I simply want to make them look different, grayed out being a very nice distinction. My intention is for checked (+enabled) to mean include logic, checked (+disabled) to mean exclude logic, and unchecked to be ignore logic (aka OR).
At the moment, I recheck the checkbox upon the second click and change the label. I'd rather not change the label but instead change the component's appearance. I like the disabled look for this purpose.
Can I gray it out without disabling it, then?
Alternatively, can I add a separate MouseListener to "listen" to clicks on the checkbox, and programmatically only perform an action if it meets my criteria (disabled)?
Surely there's a workaround...?
I removed the ActionListener and used a MouseListener to successfully register a click on a disabled component. This works fine.
That said, I do appreciate that the disabled look may be confusing, and that standards are standards for a reason... I ended up duplicating the checkbox's font and adding a strikethrough attribute:
This has the visual distinction I was looking for, after all. Thanks for reminding me about GUI standards... :)
normalFont = jCheckBox.getFont(); Map attributes = normalFont.getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); strikethroughFont = new Font(attributes); // and programattically choosing one of the following: jCheckBox.setFont(normalFont); jCheckBox.setFont(strikethroughFont);