Duplicating custom nodes in JavaFX
Posted
by Elazar Leibovich
on Stack Overflow
See other posts from Stack Overflow
or by Elazar Leibovich
Published on 2009-09-06T11:32:54Z
Indexed on
2010/04/16
21:43 UTC
Read the original article
Hit count: 303
javafx
As far as I understand, duplicating nodes in JavaFX should be done with the Duplicator.duplicate
function.
It works fine when duplicating nodes whose types are included in JavaFX library, for example
def dup = Duplicator.duplicate(Rectangle{x:30 y:30 width:100 height:100});
dup.translateX = 10;
insert dup into content;
would insert a black rectangle to the scene.
However if I define a new class in the following way:
class MyRect extends Rectangle {}
Or
class MyRect extends CustomNode {
override function create() {Rectangle{x:30 y:30 width:10 height:10}}
}
It gives me the following runtime error
Type 'javafxapplication1.NumberGrid$MyRect' not found.
Where of course javafxapplication1.NumberGrid
are the package and file the MyRect
class is in.
This guy at Sun's forums had the same problem, but I don't see any answer in there.
Or maybe I'm doing that the wrong way, and there's a better approach for duplicating custom nodes?
update: Trying to duplicate Group
worked, but trying to duplicate Stack
yields the same error.
According to the documentation, it's supposed to support all types supported in FXD
including Node
, but maybe it supports only some of Node
's descendants?
© Stack Overflow or respective owner