使用groovy的swingbuilder我想添加一个保存和退出按钮,但我无法弄清楚如何用swingbuilder关闭一个框架?由于我没有将帧分配给对象,因此我无法做frame.dispose()或类似的事情。
swingBuilder.edt {
frame(title: 'Calc Spell Checker', size: [800, 600],
show: true, locationRelativeTo: null,
defaultCloseOperation: 1) {
borderLayout(vgap: 5)
panel(constraints: BorderLayout.CENTER,
border: compoundBorder([emptyBorder(10), titledBorder("Spell Checking pole ${projProp.location} in project ${projProp.projectName}")])) {
tableLayout {
tr {
td {
label 'Comments: '
}
td {
scrollPane(verticalScrollBarPolicy:JScrollPane.VERTICAL_SCROLLBAR_ALWAYS) {
list listData: projProp.comments, fixedCellWidth: 600, visibleRowCount: 6
}
}
}
tr {
td {
label 'Suggestions: '
}
}
tr {
td {
button text: 'Replace'
}
td {
button text: 'Ignore'
}
td {
button text: 'Close', actionPerformed: {
f.SetVisible(false)
}
}
}
}
}
}
}
答案 0 :(得分:0)
所以,要做到这一点,事实证明你只需要在构建器中将框架设置为变量,然后像这样调用dispose():
guiFrame = frame(title: 'Spell Checker', size: [800, 600],
show: true, locationRelativeTo: null,
defaultCloseOperation: 1) {
int commentIndex = 0
int remedyIndex = 0
borderLayout(vgap: 5)
panel(constraints: BorderLayout.CENTER,
border: compoundBorder([emptyBorder(10), titledBorder("Spell Checking pole ${projProp.location} in project ${projProp.projectName}")])) {
tableLayout {
tr {
td {
button text: 'Replace'
}
td {
button text: 'Ignore'
}
td {
button text: 'Close', actionPerformed: {
guiFrame.dispose()
}
}
}
}
}