【问题标题】:Updating Griffon JavaFX combo boxes更新 Griffon JavaFX 组合框
【发布时间】:2013-02-23 06:00:07
【问题描述】:

我正在尝试更新组合框的内容(使用 Griffon 1.2.0,带有 JavaFX 插件)。

我的模特:

class MyModel {
    List monthList = FXCollections.observableList([new DateMidnight()])

    def convertDate = [
            fromString: { String s ->
                return new DateMidnight(DateTimeFormat.forPattern("yyyy-MM").parseDateTime(s))
            },
            toString: { DateMidnight d ->
                return "2011-10"
            }
    ] as StringConverter
}

我的观点包含:

comboBox(items: (model.monthList), converter: model.convertDate)

现在我有一个控制器动作,当他们按下按钮时会被调用:

def load = {
        execInsideUIAsync {
            def months = myService.buildMonthList()
            model.monthList.addAll(months)
        }
} 

问题在于组合框的内容永远不会改变。谁能帮我理解我错过了什么?

目前还没有关于 ComboBox 的文档http://groovyfx.org/docs/guide/single.html#choiceBoxComboBox

另外,我是否正确实现了转换器?

【问题讨论】:

    标签: combobox javafx griffon


    【解决方案1】:

    问题在于 GroovyFX.comboBox 创建了一个新列表,而不是使用您作为项目参数传递的列表: tableView 也会出现此问题。一个临时的解决方法是直接设置 items 属性,像这样

     comboBox(id: 'combo')
     noparent { combo.items = model.monthList }
    

    【讨论】:

    • 不幸的是,这对我不起作用。我已经定义了我的组合框:comboBox(id: 'months', converter: model.convertDate),然后使用了 noparent 块:noparent {months.items = model.monthList,然后在我的控制器中我更新了模型 model.monthList。 clear() model.monthList.addAll(months) 但视图永远不会改变。我曾经能够操纵组合框的唯一方法是直接访问 view.months.items 并直接清除/填充它。不理想。
    • 嗯,这可能是线程问题吗?我使用 Griffon 1.2.0 和 groovyfx/javafx 0.8 运行代码。有关详细信息,请参阅gist.github.com/aalmiray/5023272。该指南也详细描述了@Threading griffon.codehaus.org/guide/latest/guide/…
    • 嘿,我创建了一个新应用程序来尝试您的示例,它运行良好。但我仍然无法让它在我现有的应用程序中运行。当我有时间时,我会尝试让它正常工作。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2017-02-08
    • 2015-03-06
    • 1970-01-01
    相关资源
    最近更新 更多