JavaFX: Template for resizable CustomNode

Creating a CustomNode is very easy. A template is unnecessary. But when this CustomNode shall be Resizable things start to become a little bit more complicated.

Therefore I have created a template that can be used:

[cc lang="c"]
public class MyCustomNode extends CustomNode, Resizable {
override var width on replace { requestLayout() }
override var height on replace { requestLayout() }
override var layoutBounds = bind BoundingBox {
width: this.width
height: this.height
}

init {
children =[
Rectangle {
width: bind width
height: bind height
}
]
}

override function getPrefWidth( number ) {
//return your pref width – hard coded values are ok for most cases
}

override function getPrefHeight( number ) {
//return your pref height – hard coded values are ok for most cases
}

/*
//It is not absolutly necessary to override those methods, but strongly recommended.
override function getMaxWidth() {
//Return the max width
}

override function getMaxHeight() {
//Return the max height
}

override function getMinWidth() {
//Return the min width
}

override function getMinHeight() {
//Return the min height
}*/
}
[/cc]

There is a post containing a template for CustomControls here.


One Response to “JavaFX: Template for resizable CustomNode”

Leave a Reply