转自:http://www.360doc.com/content/07/0509/10/17598_489989.shtml
让jtextArea跟着滚动条动
1、jtextArea.selectAll();但是这个要选中才能。。不太好。
2、jtaHistory.setCaretPosition(jtaHistory.getText().length());
这个很给力。
解释下:就是设置文本插入符的位置。这个位置是个Int型,在0和最大length之间。
3、来自网上:本人未测试过。
recvScrollPane.getViewport().add(recvArea, null);
int height = 20;
Point p = new Point();
p.setLocation(0, recvArea.getLineCount() * height);
recvScrollPane.getViewport().setViewPosition(p);
或者同上类似的写法:
把JTextArea放在JScrollPane里,在JTextArea上调用scrollRectToVisible方法
textArea.scrollRectToVisible(new Rectangle(0, textArea.getHeight(), 0, 0));