Javafx 如何在直线内添加垂直直线
以下是我的代码:Javafx 如何在直线内添加垂直直线,javafx,line,scene,Javafx,Line,Scene,以下是我的代码: 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);
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();
}
这是图片(如果我展示图片,会更清晰)
我的问题是:我想设计我的
行
,所以我想在行
中添加垂直行。我有办法做到吗?感谢您的帮助 例如,可以使用两条线来绘制:
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);
}
}
要获得如下结果:
注:也可以使用LinearGradient
s完全解决此问题