如何在线中添加垂直线

how to add vertical lines inside the line

我的代码如下:

    public void start(Stage primaryStage) throws Exception {
    Pane root = new Pane();
    Scene scene = new Scene(root, 500, 500);

    Line line = new Line(100,0,300,0);
    line.setStrokeWidth(20);
    line.setStroke(Color.YELLOW);
    root.getChildren().add(line);

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

这是图片(如果我把图片放上去会更清楚)

我的问题是:我想设计我的 line,所以我想在我的 line 中添加垂直线。有什么办法可以做到吗?感谢您的帮助!

可以用两个Line来绘制:

public class LineDemo extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        Pane root = new Pane();
        Scene scene = new Scene(root, 500, 500);

        // Background line
        Line lineBlack = new Line(98,50,302,50);
        lineBlack.setStroke(Color.BLACK);
        lineBlack.setStrokeWidth(24);
        lineBlack.setStrokeLineCap(StrokeLineCap.BUTT);

        // Top line
        Line line = new Line(100,50,300,50);
        line.setStroke(Color.YELLOW);
        line.setStrokeWidth(20);

        // Vertical lines
        line.getStrokeDashArray().addAll(20d, 2d, 40d, 2d, 82d, 2d, 20d, 2d, 30d);
        line.setStrokeLineCap(StrokeLineCap.BUTT);


        root.getChildren().addAll(lineBlack, line);

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


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

得到如下结果:

注:用LinearGradients也可以完全解决。