JavaFX: Adding circle to line group

This entry is part 52 of 55 in the series JavaFX

For purpose of demonstration, we see how easy it is to add another drawing to the line group.

The main line that we are using is

group.getChildren().add(circle);

This put the circle to be in the same group as the line group.

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();

        // The background grid
        for (int i = 0; i < 400; i += 20) {
            Line hline = new Line(i, 0, i, 360);
            hline.setStroke(Color.LIGHTGRAY);
            Line vline = new Line(0, i, 400, i);
            vline.setStroke(Color.DARKBLUE);
            group.getChildren().addAll(hline, vline);
        }
        
        Circle circle = new Circle(200, 180, 75);
        circle.setStroke(Color.BLACK);
        circle.setFill(null);
        circle.setStrokeWidth(3);
        group.getChildren().add(circle);

        // Create the scene and the stage
        Scene scene = new Scene(group, 400, 360);
        stage.setScene(scene);
        stage.setTitle("Grid Lines and Circle");
        stage.show();
    }

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

}

group1

Series Navigation<< JavaFX: Generating grid lines using group
JavaFX: Media player >>

Leave a comment

Leave a Reply