使用GroovyFX实现新的JavaFX组件?

时间:2012-02-03 14:34:58

标签: java groovy javafx javafx-2 groovyfx

我们在项目中使用GroovyFX来构建我们的用户界面。

它已经为所有原生UI组件提供支持,例如TextAreaHTMLEditor,但我们也在构建自定义UI组件(实际上扩展了javafx.scene.web.HTMLEditor)。

在GroovyFX中实现对这个新组件的支持的最佳方法是什么?通过支持我的意思是能够像任何其他组件一样调用它:

public static void main(String[] args) {

    def myArea

    GroovyFX.start {
        new SceneGraphBuilder().stage(width: 1024, height: 700, visible: true) {
            scene {
                vbox {
                    myArea = htmlEditor()
                }
            }
        }
    }
}

2 个答案:

答案 0 :(得分:3)

你可能想看看

https://github.com/groovyfx-project/groovyfx/blob/develop/groovyfx/src/demo/groovy/CustomFieldDemo.groovy

将一个新节点类型添加到SceneGraphBuilder中,基本上是一行。

快乐开槽' @mittie

答案 1 :(得分:1)

来自GroovyFX用户列表:

  

您需要创建一个新工厂才能获得   SceneGraphBuilder识别你的myCustomEditor节点。

     

但问题的简单解决方案是写:

     

scene {vbox {       myArea = node(new MyCustomEditor())}}

     

使用node()可以添加任何对象的实例   场景图。