3
我正在使用Groovy Swingbuilder,并且想要在初始面板构建完成后动态填充单选按钮 - buttongroup。例如:我有一个有几个选项的面板。根据选择哪个选项,我需要用一组单选按钮填充按钮组。每个选项的收音机选项都不相同。如何在构建面板后动态地将按钮组添加到面板
我的面板会是这个样子:
panel(id:"chooseClass", visible:true, layout: new BL()){
vbox(constraints: BL.CENTER){
label("Player Statistics", horizontalAlignment: 0)
label(id: 'raceLabel', text: raceLabelText, horizontalAlignment: 0)
label(id: 'statLabel', text: statLabelText, horizontalAlignment: 0)
panel(id:'classGroupPanel', layout: new GridLayout(1,9)){
myButtonGroup = buttonGroup(id:'classGroup')
}
}
}
再后来在我的代码我有这样的方法:
def void setClassGroup(){
def classButtons = plyGen.getAvailibleClass()
// this is one way I've tried it
gPane.edt{panel(id:'classGroupPanel', layout: new GridLayout(1,9)){
buttonGroup(id:'classGroup').with{ group ->
classButtonGroup.each{ radioButton(id: '${it.name}', CreateRadio("${it.name}"), mnemonic:"${it.mnenomic}", buttonGroup: group)}}
}
}
// and this is another way I've tried it
gPane.doOutside {
this.classGroupPanel{
buttonGroup(id:'classGroup').with{group ->
classButtons.each{ gPane.radioButton(id: '${it.name}', CreateRadio("${it.name}"), mnemonic:"${it.mnenomic}", buttonGroup: myButtonGroup) }
}
}
}
}
这两种尝试编译和运行没有错误,但我不” t获取单选按钮列表。我希望有更多关于swingbuilder的文档。
对不起,花了这么长的时间才能接受这个答案。忙于其他事情。这个例子很好地指出我如何实现我所需要的。谢谢你会 – TroyB
哇,我没有记得这个问题! :-D。很高兴帮助 – Will
这是一个非常有帮助的问答,我很惊讶这个答案自2012年以来有0票(和问题1)! +1 –