Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to scroll by code

 
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: 2703
10
  • 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: 20822
68
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: 2703
10
  • 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: 20822
68
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.
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!