开发者

Weird problem when adding items to JavaFX sequence

开发者 https://www.devze.com 2023-01-05 17:02 出处:网络
I here met a weird problem when adding items to JavaFX sequence, the code is as be开发者_Python百科low,

I here met a weird problem when adding items to JavaFX sequence, the code is as be开发者_Python百科low,

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消