As OttPrime notes in his answer and in the Mnemonic Javadoc:
When a Mnemonic registered on the Scene , and the KeyCombination reaches the Scene intact, then the target Node will be sent an ActionEvent .
Now I think this is kind of a problem, because you really do not want the ActionEvent be sent to the ActionEvent , instead you want the fire() radio button.
Toggles the state of the switch if and only if RadioButton has not yet selected or is not part of ToggleGroup.
Note: turning on the radio button will also send the ActionEvent button to the button.
Here is the Java 8u40 code for Button::fire
@Override public void fire() { if (!isDisabled()) { fireEvent(new ActionEvent()); } }
Here is the code for ToggleButton::fire
@Override public void fire() {
And here is the code for RadioButton::fire
@Override public void fire() {
Note. RadioButton is ToggleButton, so calling super.fire () calls the ToggleButton fire () code.
So, the mnemonics for the button will be fine: all that the mnemonics does is send an ActionEvent to the button (which is exactly the same as implementing the fire for the button). However, ToggleButtons and RadioButtons do additional things in their fire methods to control the state of the ToggleButton selection, so mnemonic calls are not going to do this.
Now you can say that itโs good that I just use the OttPrime workaround:
rb1.setOnAction(event -> rb1.setSelected(!rb1.isSelected()));
It will be great if you select a button using mnemonics, but (as far as I can see), it will violate other functions for selecting buttons (for example, if you programmatically launch a switch and, possibly, also if you click on a switch with the mouse). This is because the state of the button selection will change twice (once in the fire code () and again in your action code), and you probably do not want this. Unfortunately, I cannot verify this theory, since I do not have access to a machine that can use mnemonics.
So, to answer your original question: "How does mnemonics work with radio buttons"? => They are not (at least in IMO, in no way make sense).
I would suggest just disabling Mnemonic analysis for the switches and toggle buttons.