Custom node: probs with DnD background

Hi again!

According to this thread I am currently creating my own custom node. I created a test application and after getting #layoutChildren right, I put my node into a palette and dragged it onto my view. What I get there is a node with two seperate backgrounds (JGoRoundRect) way apart of each other. I still can’t figure out where the second one comes from.

Please see this screenshot and code snippet below:

public class ProcessStepNode extends JGoNode {

    private JGoText myLabel;
    private JGoObject myBackground;    
    private JGoStroke myDivider;


    protected void copyChildren(JGoArea newarea, JGoCopyEnvironment env) {
        ProcessStepNode newobj = (ProcessStepNode) newarea;                                            
        super.copyChildren(newarea, env);
        newobj.myBackground = (JGoObject)env.get(myBackground);
        newobj.myLabel = (JGoText)env.get(myLabel);
        newobj.myDivider = (JGoStroke)env.get(myDivider);    


Sorry, forgot the selection of the nodes. See this updated screenshot. As you can see, directly after dropping the second (and unwanted) background is outside the node’s bounding rect.

Does your default constructor create and add some child objects?
If so, a copy will create two sets of child objects – those created by the constructor, and those copied by JGoArea.copyChildren.
You’ll note that most JGoArea-derived classes have a default constructor that does not create child objects, and another constructor that does and/or another method for initializing the class.

Thanks for pointing this out. I fixed my code and everything works as it should for now.