JavaFX: Generating grid lines using group

This entry is part 51 of 55 in the series JavaFX

Using  group, we can create 2 separate set of lines making them to look like grids.

Here the grids are formed by 2 groups of horizontal and vertical lines.

package drawing;

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

public class Drawing extends Application {

    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);
            Line vline = new Line(0, i, 400, i);
            group.getChildren().addAll(hline, vline);

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

    public static void main(String[] args) {



Series Navigation<< JavaFX: Webview
JavaFX: Adding circle to line group >>