JavaFX auto-scroll down scrollpane

后端 未结 6 940
轻奢々
轻奢々 2020-12-10 22:12

Is there any way of auto scroll down a ScrollPane control when it content\'s height increases ? For example, I have a TitledPane on the bottom of the screen (inside a Scroll

6条回答
  •  爱一瞬间的悲伤
    2020-12-10 22:33

    Donno if it is still relevant, I have had a similar issue-ish and this solution worked for me. I needed the scrollbar to auto scroll in an MVVM pattern. What I did was to bind the textarea's scrollTopProperty in the View with a SimpleDoubleProperty in the ViewModel. The only issue is that the scrollTopProperty, basically scrolls based on pixel so I increased it based on the number of lanes * 100;

    View

    textArea.textProperty().bindBidirectional(viewModel.SimpleStringProperty());
    textArea.scrollTopProperty().bindBidirectional(viewModel.SimpleDoubleProperty());
    

    ViewModel

    SimpleDoubleProperty.setValue(SimpleStringProperty.getValue().split("\n").length * 100);
    

    I know that the code is not really representative, but if someone needs more details of the implementations I can elaborate...

提交回复
热议问题