Marcelo
Marcelo

Reputation: 4608

Implement new JavaFX components using GroovyFX?

We are using GroovyFX in our project, to build our user interfaces.

It already provides support for all the native UI components, such as TextArea and HTMLEditor, but we are also building a custom UI component (that actually extends javafx.scene.web.HTMLEditor).

What would be the best way to implement support for this new component in GroovyFX? By support I mean being able to call it like any other component:

public static void main(String[] args) {

    def myArea

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

Upvotes: 2

Views: 645

Answers (2)

Dierk König
Dierk König

Reputation: 31

you may want to have a look at

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

which adds a new node type to the SceneGraphBuilder in essentially one line.

happy grooving' @mittie

Upvotes: 3

Marcelo
Marcelo

Reputation: 4608

From the GroovyFX-users list:

You would need to create a new factory in order to get the SceneGraphBuilder to recognize your myCustomEditor node.

But the simple solution to your problem is to write:

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

Using node() you can add an instance of any object that is-a node to the scene graph.

Upvotes: 1

Related Questions