首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GroovyFX:如何将集合绑定到表以进行动态更新?

GroovyFX:如何将集合绑定到表以进行动态更新?
EN

Stack Overflow用户
提问于 2015-11-12 00:48:00
回答 1查看 346关注 0票数 0

我想在GroovyFX中将一个项的集合绑定到一个TableView,但是我不想在调用tableView()之后更新表。

我可以在JavaFX中更新表,但不能在GroovyFX中更新。我猜有一些绑定丢失了。

代码是

代码语言:javascript
复制
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") )
            }
        }
    }
}

在这个例子中,我得到一个包含"a,b,c“的单行。

在表创建之后如何用数据("d,e,f")更新表的帮助是很有帮助的。

非常感谢。

EN

回答 1

Stack Overflow用户

发布于 2016-01-12 12:25:46

我认为其中一个问题可能是这行代码:

代码语言:javascript
复制
ObservableList<Command> script = []

因为对于def someList = new ArrayList()来说,def someList = []是Groovy。

相反,您可能希望使用以下代码对其进行初始化:

代码语言:javascript
复制
ObservableList<Command> script = FXCollections.observableArrayList()

它创建了实际的ObservableList

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33655530

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档