tags:

views:

14

answers:

1

Hey guys,

I here met a weird problem when adding items to JavaFX sequence, the code is as below,

import javafx.scene.shape.*;
import javafx.scene.Group;

var seq = [Circle{}, Path{}, Rectangle{}, Ellipse{}];
var test1 = Group{};
var test2 = Group{};

function run(args : String[]) {

     test1.content = seq;
     test2.content = seq;
     println("sizeof test1: {sizeof test1.content}");
     println("sizeof test2: {sizeof test2.content}");
}

It seems to be simple: The sequence 'seq' contains 4 nodes. Now I wish to pass the items of seq to two groups test1 and test2 respectively. However the output result is really weird,

sizeof test1: 0
sizeof test2: 4

After assignment test1.content = seq, the size of test1 has been 4 already. However after test2.content.seq the group test1 has been cleared again.

How is this happening? Any comments?

+1  A: 

if assigning controls to container.content you are making this container also parent of this controls. And there is only one parent at any time. So, it is correct behavior. You assign seq to test1.content and then are all elements removed before adding to test2.content.

Rastislav Komara