0

I want to bind a collection of items to a TableView in GroovyFX, but I'm not getting the table updated after tableView() is called.

I can update the table in JavaFX, but not in GroovyFX. I guess there's some binding missing.

Code is

import static groovyx.javafx.GroovyFX.start

import groovyx.javafx.beans.FXBindable;
import javafx.scene.control.TableView

class Command {

    @FXBindable String command
    @FXBindable String target
    @FXBindable String value
}

start{

TableView scriptTable
ObservableList<Command> script = []

stage(title: 'Example for Stackoverflow', visible: true) {

    scene(fill: groovyblue, width: 600, height: 250) {
        borderPane{
            center(align: CENTER){

                script.add( new Command(command: "a", value: "b", target: "c") )

                scriptTable = tableView(items: script, editable: true){
                    tableColumn(text: "Command", property: "command"){}
                    tableColumn(text: "Target", property: "target"){}
                    tableColumn(text: "Value", property: "value"){}
                }

                script.add( new Command(command: "d", value: "e", target: "f") )
            }
        }
    }
}

In this example I get a single row with "a, b, c". enter image description here

Help is appreciated on how to update the table with data ("d, e, f") after its creation.

Many thanks.

alexramos
  • 61
  • 7
  • Trying now with `tableView(items: bind(script), editable: true)` but that gives me `java.lang.RuntimeException: Failed to create component for 'bind' reason: java.lang.NullPointerException` – alexramos Nov 11 '15 at 17:57

1 Answers1

0

I think one of the problems might be this line of code:

ObservableList<Command> script = []

because def someList = [] is Groovy for def someList = new ArrayList().

Instead, you might want to initialize it with this code:

ObservableList<Command> script = FXCollections.observableArrayList()

which creates the actual ObservableList