简体   繁体   中英

Move 2 scroll bar at same time

In my JavaFX project I have a 2 TextFlows in a splitpane wrapped in 2 scroll panes. How can I scroll both scroll panes at same time. Or simply bind scroll bar to other scroll bar?

在此处输入图片说明

I was able to fix this by adding event listener to vvaluepropert of each scrollpane. I'm posting the answer here. SO if someone need hope this will help.

scrolPane1.vvalueProperty().addListener(new ChangeListener<Number>() {
      @Override
      public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
             if((Double)newValue < scrolPane2.getVmax())
                   scrolPane2.setVvalue((Double)newValue);
      }
});

scrolPane2.vvalueProperty().addListener(new ChangeListener<Number>() {
      @Override
      public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
             if((Double)newValue < scrolPane1.getVmax())
                  scrolPane1.setVvalue((Double)newValue);
      }
});

This would also solve your problem:

scrolPane1.vvalueProperty().bindBiderectional(scrolPane2.vvalueProperty());

That's it! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM