JTextPane或JTextPane设置了滚动条,文本增加后,滚动条自动下滑
例如:日志打印窗口,日志增加后,滚动条自动下滑,显示最新的日志。
实现方法:将光标移动到文本的最后。
JTextArea的实现:
//实现垂直滚动条自动下滑到最低端msgShowTxtPane.setCaretPosition(msgShowTxtPane.getStyledDocument().getLength());
?