Solved

How to set the scrollbar always at the bottom

Posted on 2004-09-28
4
315 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now