groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andres Almiray <aalmi...@gmail.com>
Subject Re: GroovyFx binding to two properties
Date Fri, 20 Jan 2017 13:36:45 GMT
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)
https://github.com/TomasMikula/EasyBind

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.

Cheers,
Andres

On Fri, Jan 20, 2017 at 2:23 PM, Tx. T <txt8888@yahoo.com> 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() })
>             }
>         }
>     }
> }
>
>

Mime
View raw message