• Post Reply Bookmark Topic Watch Topic
  • New Topic

JScrollPane: Auto-Scroll as Text is entered into the JTextComponent it is bound to  RSS feed

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I have a JScrollPane that is bound to a JTextPane. As data is appended to the JTextPane I wanted the JScrollPane to scroll automatically to the bottom to display the new data that has been entered.
Are there any listeners associated with the JScrollPane?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JScrollPane listens to its child (view) component for changes. JScrollPane extends JTextComponent which has useful methods. Try
textPane.setCaretPosition(textPane.getDocument().getLength())
 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Craig,
It worked! Thank you very much. The above suggestion did the trick.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!