Ali Ben Messaoud
Ali Ben Messaoud

Reputation: 11920

Problem with JTextPane - cursor Position at the end

I have a JTextpane that I had populated it from DB.

The problem is when I set text, and when it's long, the JTextPane show the text from the end like in the snapshot.

How can I do ?? I tried setCursor() but I seem it isn't the right method.

enter image description here

Upvotes: 0

Views: 1137

Answers (2)

user2845064
user2845064

Reputation: 71

recordTP = new JTextPane();
    recordTP.setText(" from client:");
    recordTP.setEditable(false);
    DefaultCaret caret = (DefaultCaret)recordTP.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

Upvotes: 0

camickr
camickr

Reputation: 324118

You can do something like:

JTextPane textPane = new JTextPane();
DefaultCaret caret = (DefaultCaret)textPane.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
textPane.setText(...);

See Text Area Scrolling for more info.

Upvotes: 3

Related Questions