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

how to scroll by code  RSS feed

 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks!

The situation:

I have a JTextArea embedded in a JScrollPanel which allows to scroll the text vertically.
The textarea serves as a kind of a log pane in my application, adding functional steps line by line to the area from top to bottom.

The problem:

Automatic scrolling is done in a way that always the first logs are displayed in the area. If the user wants to see the last logs he has to manually scroll down.

My question:

How is it possible to enable the last statements being displayed in the area instead of the first ones?

Kind regards,
Andy
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should happen automatically, if not you are doing something wrong. Read the Text Area Scrolling suggestions.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

thanks for this interesting link!

I would use this to solve the problem:


Kind regards,
Andy
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:This should happen automatically

Only if you set the caret position. By default, append leaves the caret position as it was and therefore no scrolling is done.
 
Rob Camick
Ranch Hand
Posts: 2801
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default, append leaves the caret position as it was and therefore no scrolling is done.


Not completely accurate. Check my link for conditions when the above statement is or is not true.
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never even knew that. Thanks for the update.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!