I used the following code to auto scroll the JTextArea while the program is running.
private javax.swing.JTextArea outLog;
...
DefaultCaret caret = (DefaultCaret)outLog.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
While, I want to auto scroll the lines (vertical scroll), it actually auto scrolls the columns (horizontal scroll) as well. I don't want that because by updating the columns, it stick to the last columns and I am not able to see the subsequent lines which has less columns.
How to fix that?
Check out Smart Scrolling
It managers the scrolling without using the caret policy. So you are in better control of the scrolling functionality.
If uses an AdjustmentListener on the vertical scrollbar to determine when scrolling should be done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.