Solved

How to set the scrollbar always at the bottom

Posted on 2004-09-28
4
319 Views
Last Modified: 2008-02-01
My program has a JScrollPane, it contains a JTextArea. The program will read in text and print it onto the JTextArea. But as the text getting large and longer, the scrollbar moves up-words. I have to use the mause to droll the scrollbar to the bottom so I can see the whole text. How can I set the scrollbar always on the bottom of the textarea as text is printed?
0
Comment
Question by:chenwei
  • 3
4 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 12169019
If I understand correctly you need to display the text area as the text occupies more and more of the screen. Use the setCaretPosition() and pass it the length of the text. Thsi will make the text area visible to the last line always.
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 12169026
Try:

textArea.setCaretPosition( textArea.getText().length() );
0
 

Expert Comment

by:kimos123
ID: 12169144
use  printed text + new text
0
 
LVL 35

Expert Comment

by:girionis
ID: 12169319
:)
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question