0

使用 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)
                            }
                        }
                    }
                }
            }
        }
    }
4

1 回答 1

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()
                                }
                            }
                        }
                    }
                }
于 2017-07-11T13:41:36.520 回答