-
JTextArea adjustment
I've created a JTextArea and I'm able to move it to a new location. Code is something like this:
Code:
textArea = new JTextArea(45, 35);
textArea.setEditable(false);
scrollPane = new JScrollPane(textArea);
mainPanel.add(scrollPane);
scrollPane.setLocation(775,BORDER);
textArea.setBackground(Color.GRAY);
scrollPane.f
textArea/scrollPane are defined above this section. Everything works just fine except when the text I'm adding to the textArea gets to the bottom of the textArea and forces a Scroll Bar, it doesn't automatically scroll down to see the newest text. What am I missing? How can I force this to auto scroll down.
Thanks
-
Found this out on the INTERWEBS:
textArea.setCaretPosition(textArea.getDocument().g etLength());
Sets the cursor position to the bottom of the new appended text. In conclusion auto scrolls down each time new text is appended.
Sorry for posting without doing enough research but for those who may stumble upon this problem yourself give this a shot.
-
Yep, that's exactly what I encountered on first actual use, how do ( code ) detect caret.notVisible() without wasting resources?
-
And if you wish to avoid the default scrolling, or need greater flexibilty check out Rob Camick's blog posts.
Text Area Scrolling « Java Tips Weblog
Text Utilities « Java Tips Weblog
db