JavaFX: Putting drawings into group

This entry is part 49 of 55 in the series JavaFX

A group is an ObservableList and will take on the collective bounds of its children and is not directly resizable.

In another words, will will be able to set the absolute positions of the drawings if we put them into group.  So this allows us to better control the positions of the drawings.

package drawing;

import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;

public class Drawing extends Application {

    @Override
    public void start(Stage stage) {

        Group group = new Group();

        Rectangle rect = new Rectangle(150, 100, 200, 150);
        rect.setStroke(Color.BLACK);
        rect.setFill(null);
        rect.setStrokeWidth(1);
        group.getChildren().add(rect);

        Circle circle = new Circle(150, 250, 75);
        circle.setStroke(Color.BLACK);
        circle.setFill(null);
        circle.setStrokeWidth(3);
        group.getChildren().add(circle);

        Scene scene = new Scene(group, 400, 400);
        stage.setScene(scene);
        stage.setTitle("Codecrawl.com");
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

group

 

Series Navigation<< JavaFX: Hyperlink
JavaFX: Webview >>