Adding Rectangles to Group
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.WHITE);
Group g = new Group();
for (int i = 0; i < 50; i++) {
Rectangle r = new Rectangle();
r.setY(i * 20);
r.setWidth(100);
r.setHeight(10);
r.setFill(Color.RED);
g.getChildren().add(r);
}
root.getChildren().add(g);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Related examples in the same category