JavaFX How to - Bind Arc center X property to Scene height property








Question

We would like to know how to bind Arc center X property to Scene height property.

Answer

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.stage.Stage;
// w w  w  .ja  v  a  2 s  .c  om
public class Main extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Text Fonts");

        Group g = new Group();
        Scene scene = new Scene(g, 550, 250);

        Arc arc = new Arc();
        arc.setCenterX(50.0f);
        arc.setCenterY(50.0f);
        arc.setRadiusX(25.0f);
        arc.setRadiusY(25.0f);
        arc.setStartAngle(45.0f);
        arc.setLength(270.0f);
        arc.setType(ArcType.ROUND);
        
        g.getChildren().add(arc);
        
        arc.centerXProperty().bind(scene.heightProperty().subtract(10));
        
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}