tags:

views:

177

answers:

1

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?

A: 

I know its an old question, but did you try the following?

public class MyRect extends CustomNode, Cloneable {

    override public function clone(): MyRect {
        super.clone() as MyRect;
    }
    ...    
}

Which works for me via

var newRect = rect.clone();

Which is not a deep copy (but in my case I didn't need this)

Karussell