This discussion is archived
2 Replies Latest reply: May 8, 2012 11:06 AM by jsmith RSS

Bind two Sliders

931470 Newbie
Currently Being Moderated

Allow for two sliders to move independently of each other. When a button is pressed bind them together, hence when one moves up the other moves up.. Note: the sliders need to increment the same and not both just have the same value.. Please see my source below:

Thanks for any help

public class SliderBinding extends Application {

* @param args the command line arguments
public static void main(String[] args) {

public void start(Stage primaryStage) {
primaryStage.setTitle("Bind Slider Example");

HBox hbox = new HBox();
hbox.setPadding(new Insets(15, 12, 15, 12));

final Slider slider = new Slider();

final Slider slider2 = new Slider();

final Button bind = new Button("Bind");
bind.setOnAction(new EventHandler<ActionEvent>() {

public void handle(ActionEvent event)
// The below is the issue as this just sets one value to another, is there anyway of moving up or down the amount that a slider has moved??

Scene scene = new Scene(hbox, 763,563);

  • 1. Re: Bind two Sliders
    shakir.gusaroff Expert
    Currently Being Moderated
    How about this:

    bind.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    slider.valueProperty().addListener(new ChangeListener<Number>() {
                        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                            slider2.valueProperty().set(slider2.valueProperty().get() + newValue.doubleValue() - oldValue.doubleValue() );
  • 2. Re: Bind two Sliders
    jsmith Guru
    Currently Being Moderated
    The following binds a slider to a text field, but some of the concepts in it are equally applicable to binding two sliders together. "     JavaFX example of binding a slider value to a Label or editable TextField. "


  • Correct Answers - 10 points
  • Helpful Answers - 5 points