[英]How to autoscroll JScrollPane with JTextArea inside to the left
I have private JTextArea opisDiagnoza;
我有private JTextArea opisDiagnoza;
I insert it into JScrollPane jsp
, like this: 我将其插入JScrollPane jsp
,如下所示:
opisDiagnoza = new JTextArea("Opis diagnozy:\n");
JScrollPane jsp = new JScrollPane(opisDiagnoza, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Later on, when I do: 稍后,当我这样做时:
opisDiagnoza.setText(REALLY_LONG_TEXT);
the JScrollPane
autorscrolls to right, so to read the content I need to manually(by clicking horizontal scrollbar) scroll it to the left. JScrollPane
自动向右滚动,因此要读取内容,我需要手动(通过单击水平滚动条)将其向左滚动。
How to autoscroll JScrollPane
to the left after inserting a text into JTextArea
inside of it? 在将文本插入到JTextArea
内部后,如何将JScrollPane
自动向左滚动?
Example: 例:
http://i.stack.imgur.com/fxc4x.png http://i.stack.imgur.com/fxc4x.png
I can't add image explicitly because of low reputation. 由于信誉低下,我无法明确添加图片。
Try this 尝试这个
DefaultCaret caret = (DefaultCaret)textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.