Posted By

laurenceosx on 01/14/11


Tagged

groovy


Versions (?)

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


 / Published in: Groovy
 

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

  1. import groovy.swing.SwingBuilder
  2. import groovy.beans.Bindable
  3.  
  4. class MyModel {
  5. @Bindable int count = 0
  6. }
  7.  
  8. def model = new MyModel()
  9. new SwingBuilder().edt {
  10. frame(title: "Java Frame", size: [100, 100], locationRelativeTo: null, show: true) {
  11. gridLayout(cols: 1, rows: 2)
  12.  
  13. // OLD - does not display until assigned a different value than the original
  14. // label(text: bind(source: model, sourceProperty: "count", converter: { v -> v? "Clicked $v times": ''}))
  15.  
  16. // NEW - this works
  17. label( text: bind(source: model, sourceProperty: "count", converter: { v -> "Clicked $v times" }) )
  18.  
  19.  
  20. button("Click me!", actionPerformed: { model.count++ })
  21. }
  22. }

Report this snippet  

You need to login to post a comment.