keep JScrollPane at bottom

Posted on 2005-04-02
Medium Priority
Last Modified: 2010-05-18
As I add text to a JTextPane which is in a JScrollPane, how can I keep the JScrollPane at the bottom, in other words, make it so I don't need to scroll down every time I add text to it.  

I'm guessing I would want to keep updating the viewPosition, but I'm not sure how to do that.  Maybe get the bottom corner of the accessibleContext into a Point somehow???
Question by:ARACK04
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 92

Accepted Solution

objects earned 2000 total points
ID: 13690929
Call setCaretPosition() after adding text
LVL 92

Expert Comment

ID: 13690931
textArea.setCaretPosition( textArea.getText().length() );
LVL 30

Expert Comment

by:Mayank S
ID: 13691233
Or you can try calling the setValue () method of the veritical scroll-bar.
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more


Author Comment

ID: 13691863
Thanks, just so you don't think I'm terribly stupid, I was looking in the JScollPane documentation...which is why I missed that method...of course if I really was *not stupid* I suppose I would have looking in JTextPane.  Anyway, thanks
LVL 92

Expert Comment

ID: 13693913
I don't think you're stupid :)
LVL 30

Expert Comment

by:Mayank S
ID: 13695444
>> I was looking in the JScollPane documentation

You would find getverticalScrollbar () in it ;-) and then setValue () in JScrollbar.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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