开发者

Problem with JTextPane - cursor Position at the end

开发者 https://www.devze.com 2023-03-02 20:48 出处:网络
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.

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.

开发者_JAVA技巧

Problem with JTextPane - cursor Position at the end


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消