Example usage for javafx.scene.shape Line setStrokeDashOffset

List of usage examples for javafx.scene.shape Line setStrokeDashOffset

Introduction

In this page you can find the example usage for javafx.scene.shape Line setStrokeDashOffset.

Prototype

public final void setStrokeDashOffset(double value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Drawing 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);//from w w  w  .j a  v a  2s  .  c o m
    redLine.setStrokeLineCap(StrokeLineCap.BUTT);

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

    root.getChildren().add(redLine);

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

From source file:Main.java

@Override
public void start(Stage primaryStage) {

    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);//w w  w.  j a  v  a2 s  . co m
    redLine.setStrokeLineCap(StrokeLineCap.BUTT);

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

    root.getChildren().add(redLine);

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

    root.getChildren().add(offsetText);

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

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

    slider.valueProperty().addListener(
            (ov, curVal, newVal) -> offsetText.setText("Stroke Dash Offset: " + slider.getValue()));

    root.getChildren().add(slider);

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