Using Pane as Canvas
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 260, 80);
stage.setScene(scene);
stage.setTitle("");
VBox vb = new VBox();
Pane canvas = new Pane();
canvas.setStyle("-fx-background-color: black;");
canvas.setPrefSize(200,200);
Circle circle = new Circle(50,Color.BLUE);
circle.relocate(20, 20);
Rectangle rectangle = new Rectangle(100,100,Color.RED);
rectangle.relocate(70,70);
canvas.getChildren().addAll(circle,rectangle);
vb.getChildren().add(canvas);
scene.setRoot(vb);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Related examples in the same category