JavaFX How to - Control line connection with StrokeLineCap.BUTT








Question

We would like to know how to control line connection with StrokeLineCap.BUTT.

Answer

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeLineCap;
import javafx.stage.Stage;
/*from w w  w .java 2 s  . c om*/
public class Main extends Application {
    @Override
    public void start(Stage stage) {
        Group root = new Group();
        Scene scene = new Scene(root, 500, 200);
        stage.setScene(scene);
        
        
        Rectangle rect = new Rectangle(100,100); 
        rect.setLayoutX(50); 
        rect.setLayoutY(50); 
        rect.setStrokeLineCap(StrokeLineCap.BUTT); 
        ((Group)scene.getRoot()).getChildren().add(rect);
        

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