Return to Snippet

Revision: 39185
at January 14, 2011 06:48 by laurenceosx


Initial Code
import groovy.swing.SwingBuilder
import groovy.beans.Bindable

class MyModel {
   @Bindable int count = 0
}

def model = new MyModel()
new SwingBuilder().edt {
  frame(title: "Java Frame", size: [100, 100], locationRelativeTo: null, show: true) {
    gridLayout(cols: 1, rows: 2)

    // OLD - does not display until assigned a different value than the original
    // label(text: bind(source: model, sourceProperty: "count", converter: { v ->  v? "Clicked $v times": ''}))

    // NEW - this works
    label( text: bind(source: model, sourceProperty: "count", converter: { v -> "Clicked $v times" }) )


    button("Click me!", actionPerformed: { model.count++ })
  }
}

Initial URL
http://groovy.codehaus.org/Swing+Builder

Initial Description

                                

Initial Title
Groovy Swing data binding example that works on a freshly created object (online example does not)

Initial Tags
groovy

Initial Language
Groovy