Skip to main content

Add node to a group at runtime?

3 replies [Last post]
kram
Offline
Joined: 2007-10-23

Im only new to javafx...I guess most people still are, but I was wondering if it is possible to add a node to a Group at runtime when the user clicks the mouse?

Thanks
Mark

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12

You can create a sequence of nodes and bind the sequence to a Group content.
Inserting a node to the sequence or a deleting a node from it will repaint an app.

For example:

[code]
import javafx.application.*;

import javafx.scene.*;
import javafx.scene.text.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
import javafx.input.MouseEvent;

var nodes:Node[] = [
Circle{
radius: 30
fill: Color.ORANGE
onMouseClicked: function( e: MouseEvent ):Void {
insert Circle{
centerX: sizeof nodes * 50
centerY: sizeof nodes * 50
radius: 20
fill: Color.BLUE
} into nodes;
}
}
];

Frame {
title: "MyApplication"
width: 500
height: 500

stage: Stage {
content: Group{
content: bind nodes;
}
}
visible: true
}
[/code]

kram
Offline
Joined: 2007-10-23

Perfect! thanks very much, thats exactly what I needed, and thanks for the quick reply.

alexsch
Offline
Joined: 2007-07-12

You are welcome!