views:

241

answers:

1

I have a JTable being constructed via Groovy's SwingBuilder. I'd like to attach a closure to the table that fires when a cell is selected, but I can't seem to find the right hook.

How do I do that?

+1  A: 

I'm not an expert in groovy, but when inside the table element of the swingbuilder, you could use the Groovy way to implement interfaces. This works because ListSelectionListener only has one method.

table(id: 'myTable') {
    myTable.selectionModel.addListSelectionListener({evt->
            println("selection changed")
        } as ListSelectionListener)
    }
Tobias Schulte