import javafx.application.Application; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Slider; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.stage.Stage; public class DashTest extends Application { public void start(Stage stage) { final Rectangle r = new Rectangle(100, 100, 100, 50); r.getStrokeDashArray().addAll(1.0, 1.0); r.setFill(null); r.setStroke(Color.BLACK); final Slider sw = new Slider(0, 4, 1); final Slider sd = new Slider(0, 4, 1); final Text tsw = new Text("stroke width = 1.0"); final Text tsd = new Text("dash length = 1.0"); r.strokeWidthProperty().bind(sw.valueProperty()); sw.valueProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable observable) { tsw.setText("stroke width = "+sw.getValue()); } }); sd.valueProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable observable) { r.getStrokeDashArray().set(0, sd.getValue()); r.getStrokeDashArray().set(1, Float.MIN_VALUE+sd.getValue()); tsd.setText("dash length = "+sd.getValue()); } }); sw.setTranslateY(200); sd.setTranslateY(200); sd.setTranslateX(150); tsw.setTranslateY(250); tsd.setTranslateY(250); tsd.setTranslateX(150); Scene scene = new Scene(new Group(r, sw, tsw, sd, tsd), 300, 300); stage.setScene(scene); stage.show(); } }