Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Scrollable TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scrollable TextArea " Watch "Scrollable TextArea " New topic

Scrollable TextArea

Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
I have a scrollable TextArea, when I add text using setText("...") the Horizantal scrollbar goes to the bottom. I want the scrollbar at the top so the use sees the text at the beginning, not the ending text.
Any ideas?
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
Yes, irritating isn't it : there should be a method like .ensureIndexIsVisible(int) like there is for Lists.
But there isn't.
You can do it as a side affect of setCaretPosition :

which is a bit cheesy... but then I suppose it's logical to only let your users start editing on the bit they can see. (Seems to work for non-editable TextArea too)
Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
That worked perfectly!
I agree. Here's the link:
subject: Scrollable TextArea
It's not a secret anymore!