如何将 JScrollPane 设置到 JTextArea 的底部?我试过
DefaultCaret caret = (DefaultCaret)getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
但它没有工作它没有自动下降。
这是我当前的代码
public class subTextAreaMessages extends JTextArea implements ActionListener{
private ArrayList al;
public subTextAreaMessages()
{
setEditable(false);
listTheMessages();
Timer t = new Timer(500,this);
t.start();
}
public void listTheMessages()
{
ConnectMysql.getUsernamesTest(this);
}
@Override
public void actionPerformed(ActionEvent e) {
try {
System.out.print(getText(185,186));
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
jspTextField = new JScrollPane(new subTextAreaMessages());
mainPanel2.add(jspTextField ,BorderLayout.CENTER);