我有一个3 JRadioButtonMenuItem
在一个菜单中,和3 JToggleButton
在工具栏中的组。它们中的每一个都绑定到3 Action
,这样当我禁用一个动作时,相应的项目和按钮都将被禁用。协调两个`ButtonGroup`
当我点击一个菜单项时,我也希望相应的工具栏按钮被选中,但似乎“unclicked”组有自己奇怪的方式来对这些事件做出反应(使用我没有的模式,尝试识别)。
这里的菜单组代码(简化):
ButtonGroup menuGrp = new ButtonGroup();
JRadioButtonMenuItem itemA = new JRadioButtonMenuItem(actionA);
JRadioButtonMenuItem itemB = new JRadioButtonMenuItem(actionB);
JRadioButtonMenuItem itemC = new JRadioButtonMenuItem(actionC);
menuGrp.add(itemA);
menuGrp.add(itemB);
menuGrp.add(itemC);
itemA.setSelected(true);
这里的工具栏组代码:
ButtonGroup toolbarGrp = new ButtonGroup();
JToggleButton buttonA = new JToggleButton(actionA);
JToggleButton buttonB = new JToggleButton(actionB);
JToggleButton buttonC = new JToggleButton(actionC);
toolbarGrp.add(buttonA);
toolbarGrp.add(buttonB);
toolbarGrp.add(buttonB);
buttonA.setSelected(true);
您将buttonB添加到toolbarGrp两次。这只是一个错字,或者你是否有代码? – 2012-03-15 02:15:01
不,这是一个错字。 – bigstones 2012-03-15 08:48:16