Reputation: 69
How can I set the JScrollPane to the bottom of the JTextArea? I tried the
DefaultCaret caret = (DefaultCaret)getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
But it didnt work it didnt automatically go down.
Here is my current code
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);
Upvotes: 0
Views: 560
Reputation: 23
I had the problem that my text was being completely replaced periodically by similar content and users wanted to keep the visible location within the large text content fixed. My solution was to implement my own BoundedRangeModel by extending the DefaultBoundedRangeModel. Then I told the ScrollPane's ScrollBars to use an instance of my model and all went well.
Upvotes: 0
Reputation: 324118
Depending on your exact requirement, one of the following should help
Upvotes: 1