Ejemplo n.º 1
0
  public void start(Stage primaryStage) {
    primaryStage.setTitle("Lines");

    Group root = new Group();
    Scene scene = new Scene(root, 300, 150, Color.GRAY);

    Line redLine = new Line(10, 10, 200, 10);

    redLine.setStroke(Color.RED);
    redLine.setStrokeWidth(10);
    redLine.setStrokeLineCap(StrokeLineCap.BUTT);

    redLine.getStrokeDashArray().addAll(10d, 5d, 15d, 5d, 20d);
    redLine.setStrokeDashOffset(0);

    root.getChildren().add(redLine);

    Line whiteLine = new Line(10, 30, 200, 30);
    whiteLine.setStroke(Color.WHITE);
    whiteLine.setStrokeWidth(10);
    whiteLine.setStrokeLineCap(StrokeLineCap.ROUND);

    root.getChildren().add(whiteLine);

    Line blueLine = new Line(10, 50, 200, 50);
    blueLine.setStroke(Color.BLUE);
    blueLine.setStrokeWidth(10);

    root.getChildren().add(blueLine);

    Slider slider = new Slider(0, 100, 0);
    slider.setLayoutX(10);
    slider.setLayoutY(95);

    redLine.strokeDashOffsetProperty().bind(slider.valueProperty());

    root.getChildren().add(slider);

    Text offsetText = new Text("Stroke Dash Offset: 0.0");
    offsetText.setX(10);
    offsetText.setY(80);
    offsetText.setStroke(Color.WHITE);

    slider
        .valueProperty()
        .addListener(
            (ov, curVal, newVal) -> offsetText.setText("Stroke Dash Offset: " + slider.getValue()));
    root.getChildren().add(offsetText);
    primaryStage.setScene(scene);
    primaryStage.show();
  }