Generated Object

javafx.scene.Parent

Value

The custom container object

Attributes

This node takes the attributes of the javafx.scene.Parent class. see javafx.scene.Parent

In addition, if a value is not present, then the following attribute is required:

container: the custom parent object

Content

This node may take general javafx node content like effects, transforms and inputs. Also it make take JavaFX nodes that are added to the custom container.

Usage

Creates a Custom Container.

Examples

import groovyx.javafx.SceneGraphBuilder
import groovyx.javafx.GroovyFX
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Region;
import javafx.geometry.HPos;
import javafx.geometry.VPos;

class SimpleContainer extends Region {

    public SimpleContainer() {
    }
    
    @Override
    protected void layoutChildren() {
        List<Node> managed = getManagedChildren();
        def width = getWidth();
        def height = getHeight();
        def partWidth = width/managed.size();
        
        def x = 0
        for(n in managed) {
            layoutInArea(n, x, 0, partWidth, height, 0,
                HPos.CENTER, VPos.CENTER);
            x += partWidth;
        }
    }
}

GroovyFX.start({
    def sg = new SceneGraphBuilder();
    sg.stage(
        title: "Custom Container example",
        x: 100, y: 100, width: 200, height:200,
        visible: true,
    ) {
        scene(fill: hsb(128, 0.5, 0.5, 0.5)) {
            container(new SimpleContainer()) {
                button(text: "one")
                button(text: "two")
                button(text: "three")
            }
        }
    }
});