1  import javafx.application.Application;
  2  import javafx.stage.Stage;
  3  import javafx.geometry.Orientation;
  4  import javafx.scene.Scene;
  5  import javafx.scene.control.Slider;
  6  import javafx.scene.layout.BorderPane;
  7  import javafx.scene.layout.Pane;
  8  import javafx.scene.text.Text;
  9  
 10  public class SliderDemo extends Application {
 11    @Override // Override the start method in the Application class
 12    public void start(Stage primaryStage) {
 13      Text text = new Text(20, 20, "JavaFX Programming");
 14      
 15      Slider slHorizontal = new Slider();
 16      slHorizontal.setShowTickLabels(true);
 17      slHorizontal.setShowTickMarks(true);    
 18      
 19      Slider slVertical = new Slider();
 20      slVertical.setOrientation(Orientation.VERTICAL);
 21      slVertical.setShowTickLabels(true);
 22      slVertical.setShowTickMarks(true);
 23      slVertical.setValue(100);
 24      
 25      // Create a text in a pane
 26      Pane paneForText = new Pane();
 27      paneForText.getChildren().add(text);
 28      
 29      // Create a border pane to hold text and scroll bars
 30      BorderPane pane = new BorderPane();
 31      pane.setCenter(paneForText);
 32      pane.setBottom(slHorizontal);
 33      pane.setRight(slVertical);
 34  
 35      slHorizontal.valueProperty().addListener(ov -> 
 36        text.setX(slHorizontal.getValue() * paneForText.getWidth() /
 37          slHorizontal.getMax()));
 38      
 39      slVertical.valueProperty().addListener(ov -> 
 40        text.setY((slVertical.getMax() - slVertical.getValue()) 
 41          * paneForText.getHeight() / slVertical.getMax()));
 42      
 43      // Create a scene and place it in the stage
 44      Scene scene = new Scene(pane, 450, 170);
 45      primaryStage.setTitle("SliderDemo"); // Set the stage title
 46      primaryStage.setScene(scene); // Place the scene in the stage
 47      primaryStage.show(); // Display the stage   
 48    }
 49  
 50    /**
 51     * The main method is only needed for the IDE with limited
 52     * JavaFX support. Not needed for running from the command line.
 53     */
 54    public static void main(String[] args) {
 55      launch(args);
 56    }
 57  }