解决方案
方法一
JTextArea.selectAll();
方法二
JTextArea.setCaretPosition(JTextArea.getText().length());
方法三
JScrollPane.getViewport().add(JTextArea,null);
Point p = new Point();
p.setLocation(0,JTextArea,getLineCount() * int);
JScrollPane.getViewprot.setViewPosition(p);
方法四
JScrollBar scrollBar = this.jScrollPane1.getVerticalScrollBar();
scrollBar.setValue(scrollBar.getMaxmium());
方法四-改进
jScrollPane1.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent evt) {
if(evt.getAdjustmentType() == AdjustmentEvent.TRACK && isNeedBottom <= 3) {
jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getModel().getMaximum() - jScrollPane1.getVerticalScrollBar().getModel().getExtent());
isNeedBottom++;
}
}
});
参考文章
https://www.cnblogs.com/donaldlee2008/p/9137880.html
https://blog.csdn.net/qq_43320407/article/details/88408099
https://blog.csdn.net/iteye_563/article/details/82516713
https://blog.csdn.net/zhizaibide1987/article/details/83909537