0

Using groovy's swingbuilder I'd like to add a save and exit button, but I can't figure out how to close a frame with the swingbuilder? Since I don't have the frame assigned to an object I can't really do frame.dispose() or anything like that.

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)
                            }
                        }
                    }
                }
            }
        }
    }
Ajv2324
  • 422
  • 8
  • 24

1 Answers1

0

So, to do this, turns out you just need to set the frame to a variable in the builder, then call dispose() on it like so:

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()
                                }
                            }
                        }
                    }
                }
Ajv2324
  • 422
  • 8
  • 24