Link between Toggle and e.g. the RadioButton behin

2019-08-30 11:42发布

问题:

Imaging e.g. 2 RadioButtons which share one ToggleGroup. Using

ToggleGroup.getToggles()

one can access all Toggles of the ToggleGroup. But is there any reference from a Toggle to the RadioButton that is linked to?

回答1:

If I understood the question correctly you're looking for:

RadioButton button = (RadioButton) toggleGroup.getSelectedToggle();

Unfortunatly, the ToggleGroup isn't "generified" yet, so you need the cast.

But is there any reference from a Toggle to the RadioButton that is linked to?

Or in other words: RadioButton is a (implements) Toggle, there isn't any reference.