Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Few notes; </p> <ol> <li>The slightly slipping of the line you have drawn, is due to the left and right margins between the border and the slider line of the slider. You can test it by changing the <code>double margin</code> value in the code below.</li> <li>You cannot use <code>slider.getWidth()</code> until the stage is shown. See the "before" and "after" printings in the code below. Instead I used <code>slider.getPrefWidth()</code>. Ofcourse if you are using getWidth() in some event handler then no problem.</li> <li>Use bindings for more easy control and coding. Slide the thumb in the code below.</li> </ol> <p>public class SliderDemo extends Application {</p> <pre><code> public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { Slider slider = new Slider(); slider.setStyle("-fx-border-color: green"); slider.setLayoutX(60); slider.setLayoutY(50); slider.setMax(200); slider.setValue(180); slider.setMin(100); slider.setPrefWidth(390); double margin = 10; // left and right margins between the border and the slider line of the slider SimpleDoubleProperty pixelsPerValueProperty = // new SimpleDoubleProperty((slider.getPrefWidth() // - (2 * margin)) / (slider.getMax() - slider.getMin())); SimpleDoubleProperty pathXProperty = new SimpleDoubleProperty(); pathXProperty.bind(slider.layoutXProperty()// .add(margin)// .add(pixelsPerValueProperty.multiply(slider.valueProperty().subtract(slider.getMin())))); MoveTo moveTo = new MoveTo(0, 0); moveTo.xProperty().bind(pathXProperty); LineTo lineTo = new LineTo(0, 25); lineTo.xProperty().bind(pathXProperty); Path path = PathBuilder.create().elements( moveTo, lineTo)// .stroke(Color.CYAN)// .strokeWidth(3)// .translateX(0)// .translateY(77.0)// .build(); Group group = new Group(slider, path); primaryStage.setScene(new Scene(group, 700, 250)); System.out.println("before slider.getWidth() = " + slider.getWidth()); primaryStage.show(); System.out.println("after slider.getWidth() = " + slider.getWidth()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload