groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tx. T" <>
Subject Re: GroovyFx binding to two properties
Date Fri, 20 Jan 2017 15:46:10 GMT
I did this but thought this was not so Groovy-ish :)

#!/usr/bin/env groovy
import static groovyx.javafx.GroovyFX.startimport javafx.beans.binding.Bindings as B
start {    stage title: "Test App", visible: true, {        scene {           
hbox {                tf1  = textField(id: "tf1")                tf2  =
textField(id: "tf2")
                button('Submit', id: "smb", disable: bind(B.or(tf1.textProperty().isEmpty(), 
 tf2.textProperty().isEmpty())))            }        }    }}

      From: Andres Almiray <>
 To:; Tx. T <> 
 Sent: Friday, January 20, 2017 7:36 AM
 Subject: Re: GroovyFx binding to two properties
You must create a composite binding. The standard JavaFX API provides a `javafx.beans.binding.Bindings`
class that can be used to create a BooleanBinding out of a group of ObservableValues.
There's also EasyBind (my personal favorite)

You may create a BooleanBinding for each textfield that computes if said textfield is empty
or not. Then you may create a composite BooleanBinding based on the previous boolean bindings.
Or you can create a single BooleanBinding based on the textProperty of each textfield directly.
Your choice.

Once you've got the binding simply apply it to the button's disable property.


On Fri, Jan 20, 2017 at 2:23 PM, Tx. T <> wrote:

how would I go about binding the textProperty of two textfields to a button's disable (on/off)?
 Here is an example of binding to 1 textfield.  I like to know how to do similar but with
2 or more textfields.Basically, if two textfields are empty, the submit button is disable,
else.#!/usr/bin/env groovy

import static groovyx.javafx.GroovyFX.start

start {
    stage title: "Test App", visible: true, {
        scene {
            hbox {
                tf = textField(id: "tf")
                button('Submit', id: "smb", disable: bind(tf.textProperty()).using { it.isEmpty()

View raw message