/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tests; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Scene; import javafx.scene.control.Slider; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * * @author sjiang */ public class SliderTest1 extends Application { public static void main(String[] args) throws Exception { Application.launch(args); } @Override public void start(Stage stage) throws Exception { VBox vbox = new VBox(5); final Slider s1 = new Slider(); Slider s2 = new Slider(); vbox.getChildren().addAll(s1, s2); Scene scene = new Scene(vbox); stage.setScene(scene); stage.setWidth(350); stage.setHeight(620); stage.show(); s1.requestFocus(); s1.focusedProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue arg0, Boolean arg1, Boolean arg2) { System.out.println("---slider focused "+arg2); if (arg2) { s1.focusedProperty().removeListener(this); } } }); } }