2013-11-25 102 views
0

某人如何检索放入切换组中的元素?或者也许有另一种方法来组织控制,以便它们可以切换,客户也可以从组内控制实际控制?检索ToggleGroup中的元素

我有什么

RadioButton radio1 = new RadioButton(); 
RadioButton radio12= new RadioButton(); 
ToggleGroup toggleGroup = new ToggleGroup(); 
radio1.setToggleGroup(toggleGroup); 
radio2.setToggleGroup(toggleGroup); 

我想要什么

RadioButton temp = toggleGroup.getSelectedObject(); 

或者

RadioButton temp = toggleGroup.getSelectedToggle().getObject(); 

回答

1

如果你想获取该组所有切换:

toggleGroup.getToggles() 

给你一个所有切换的列表。

,如果你想选择的切换:

toggleGroup.getSelectedToggle() 

给你一个切换对象。

所以我觉得在这一行RadioButton temp = toggleGroup.getSelectedObject();你要投像RadioButton temp =(RadioButton) toggleGroup.getSelectedObject();

+0

是的,我认为做的。谢谢 – cblupo