Let's say we are having some JRadioButton
s which belongs to same ButtonGroup
, when user clicks on a JRadioButton
it got selected. I want to add a feature that when user click on already selected JRadioButton
, it gets deselected, that is whole ButtonGroup
will have no JRadioButton
selected.
I already searched which leads me hint to use, ButtonGroup
method, clearSelection. but problem is that when user clicks on already selected JRadioButton, it is not generating any ItemStateChangeEvent
, which is generating by clicking on other unselected JRadioButton
s.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I'd use the approach cited. Because a
JRadioButton
is aJToggleButton
, a mouse gesture is possible but problematic. I'd use aMouseListener
on the enclosing panel and Key Bindings on the buttons as shown below. Click in the panel surrounding the buttons or press the escape key to clear the selection of all buttons in theButtonGroup
.Or, as an alternate approach, override
ButtonGroup#setSelected(...)
: