Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
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: [300100, 300100], locationRelativeTo: null, show: true) {
    gridLayout(cols: 1, rows: 2)
{       label(text: bind(source: model, sourceProperty: "count", converter: { v ->  v? "Clicked $v times": ''}))
      button("Click me!", actionPerformed: { model.count++ })
    }
  }
} 

@Bindable is one of the core AST Transformations. It generates all the required boilerplate code to turn a simple bean into an observable one. The bind() node creates appropriate PropertyChangeListeners that will update the interested parties whenever a PropertyChangeevent is fired.

...