سؤال

I have BorderPane with left and center part, both are ScrollPanes. How to scroll them with one scrollbar ( vertical ). Or how to get access to one of the ScrollBars ?

هل كانت مفيدة؟

المحلول 2

you can bind scrollpane1(sp1) vScrollBar property and set the changed value to other scrollpane vScrollbar property.

Sample code : this code automatically changes SP2 vScrollbar position when Sp1 vScrollbar position chnaged.

DoubleProperty vPosition = new SimpleDoubleProperty();
    vPosition.bind(sp1.vvalueProperty());
    vPosition.addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue arg0, Object arg1, Object arg2) {
             sp2.setVvalue((double) arg2);

        }
    }); 

Hint to get one scrolll bar to scroll two Scroll panes : Define a vertical scroll bar and then hide ( may be set opcaity to Zero or something ..) vscrollbars for two Scrollpanes. and then bind to defined scrollbar changes and set that chnaged values to both scrollpanes vscrollbars like above.

نصائح أخرى

The answer of @invariant did not work for me. But the code written below worked out.

ScrollPane sp1 = new ScrollPane();
ScrollPane sp2 = new ScrollPane();
sp1.hvalueProperty().bindBidirectional(sp2.hvalueProperty());

With the binding two components to each other, they scroll together horizontally. It would work for vertical case.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top