Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added sourceProperty example

...

Until the external API is finalized, it is not recommended to use the object returned from bind

Examples

Example binding one property to another:

Code Block
swing.frame() {
  panel {
    textField('Change Me!', id:'tf')
    button(text: bind(source:tf, sourceProperty:'text'))
  }
}

Example when triggering on a particulaer event with a value closure

Code Block

swing.frame() {
  panel {
    textField('Change Me!', id:'tf')
    button(text: bind(source:tf.document, sourceEvent:'undoableEditHappened', 
      sourceValue:{tfSystem.textcurrentTimeMillis()}))
  }
}

Note that the source value can get any arbitrary value.

Example with validator and converter:

Code Block
swing.frame() {
  panel
   {
    textField('Change Me!', id:'tf')
    button(text: bind(source:tf.document, sourceEventsourceProperty:'undoableEditHappenedtext',
sourceValue:{tf.text},      validator: { tf.text.length() >= 1}, converter: { it.toLowerCase() } ))
   }
}

The In this example the validator prevents the button text from having less than 1 char and the converter makes the button text all lowercase.

...