Imagine I'm making a simple word processor with Java Swing. I have a set of actions written to perform text alignment. On the MenuBar, I have a menu:
View
Left justify
Center jusitfy
Right justify
This consists of JRadioButtonMenuItems and ButtonGroup to ensure that only one item is selected at any time.
Also, imagine that I have an equivalent toolbar consisting of JToggleButtons and again ButtonGroup to ensure that only one button can be active at any time.
Left alignment JRadioButtonMenu and JToggleButton are initialized using the same Action, etc. with other elements.
My question is: what is the best method for synchronizing two groups? If I click "Right Justify" on the toolbar, I want the group in the menu to be updated accordingly, and vice versa.
source
share