Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping the Scroll Bar at the top of the JScrollPane  RSS feed

 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a JEditorPane with a JScrollPane. Whenever I update the text in the JEditorPane the scroll bar of the JScrollPane goes to the end of the text. This means that the user must scroll back up to the top to read from the beginning.

Is there any way to keep the scroll bar at the top when I change the text in the JEditorPane?

I have tried to use setValue() but it didn't work.

Thanks,
Ben
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setCaretPosition(0)
This method is inherited from JTextComponent - scroll down in the JEditorPane api to the section "Methods inherited from class javax.swing.text.JTextComponent" to find the method.
 
Ben Wong
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that worked a treat, thank you!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!