Subtract Shape in JavaFX - Java JavaFX

Java examples for JavaFX:Shape

Description

Subtract Shape in JavaFX

Demo Code

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Path;
import javafx.scene.shape.Shape;
import javafx.stage.Stage;

public class Main extends Application {

  public static void main(String[] args) {
    Application.launch(args);/*from   w w  w  .ja  v a2  s.co m*/
  }

  @Override
  public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 306, 550, Color.WHITE);

    Ellipse bigCircle = new Ellipse(100, 100, 50, 75 / 2);
    bigCircle.setTranslateY(123);
    bigCircle.setStrokeWidth(3);
    bigCircle.setStroke(Color.BLACK);
    bigCircle.setFill(Color.WHITE);

    Ellipse smallCircle = new Ellipse(100, 10, 35/2, 25/2);
    // make a donut
    Shape donut = Path.subtract(bigCircle, smallCircle);
    donut.setStrokeWidth(1);
    donut.setStroke(Color.BLACK);
    // orange glaze
    donut.setFill(Color.rgb(255, 200, 0));
    
    root.getChildren().add(donut);

    primaryStage.setScene(scene);
    primaryStage.show();
  }
}

Related Tutorials