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.
May 1st, 2010 at 16:29
[...] Schneider, notável e freqüente blogueiro sobre JavaFX, recentemente publicou um pequeno post onde mostra um template para a criação de nós customizados redimensionáveis: “Criar [...]