鉴于一个巨大AnchorPane的一些子节点是a的内容,ScrollPane我如何滚动制作一个在当前视口之外的子节点可见?
这是我的代码.
textArea.setText(someNewText)
textArea.positionCaret(textArea.getText().length());
textArea.setEditable(true);
textArea.setScrollTop(Double.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
我用来textArea.setScrollTop(Double.MAX_VALUE)将textarea滚动到底部(我在互联网上找到的解决方案).它有效,但并非总是如此.我注意到它只有在调用此代码之前看不到垂直滚动条并且在执行代码后可见时才能工作.在调用此代码之前显示垂直滚动条时,滚动到底部始终有效.怎么解决?也许我应该让垂直滚动条始终可见?如果是,那么如何 - 我没有找到解决方案.
编辑: 这是示例代码:
public class JavaFxApp1 extends Application{
private TextArea textArea;
@Override
public void start(Stage stage) throws Exception {
Button button=new Button("Press here");
textArea=new TextArea();
VBox vbox = new VBox(button,textArea);
button.setOnAction((event)->{
textArea.appendText("###This is a very long string:some text some text some text some text some"
+ " text some text some text some text some text some text"
+ " text some text some text some text some text some text" …Run Code Online (Sandbox Code Playgroud)