Forums Register Login

JTextArea scrolls to bottom

+Pie Number of slices to send: Send
Hi
I have a JTextArea within a JScrollPane
If I fill the textarea with too much text (programatically) I want the vertical scrollbar to be in the top.
I've tried

and even

with no luck.
Anyone have an idea?
Thanks,
Steffen
+Pie Number of slices to send: Send

look at the constructors of the JScrollPane, there are 4.
In my above example I used the
JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
the component is what I want to add to the JScrollPane, followed by constants inherited from the ScrollPaneConstants class, which tell what kind of scrollbars to use and when.
Mark
+Pie Number of slices to send: Send
Thanks Mark, but I'm afraid that won't do it.
I am using an empty constructor, but the JScrollPane has the two AS_NEEDED scrollbar policies as default.
Using the three-argument contructor explicitely didn't help either.
But thanks anyway...
Steffen
+Pie Number of slices to send: Send
I had to figure out this very problem about 4 years ago. If I remember correctly I think I used the setCaretPosition method in JTextComponent (which is a super class of JTextArea) to set the location of the curser (caret) to the upper left of the text area. That scrolled the text back to the top.
Give that a try. I'm pretty sure that's how I made it work.
+Pie Number of slices to send: Send
Call scrollRectToVisible( new Rectangle( 0, 0, 0, 0 ) ); on the actual Component you want to scroll, not on the JScrollPane...

-Nate
+Pie Number of slices to send: Send
Now it's working!!
Nathan's suggestion:

didn't solve the problem. (Sorry, Nate )
Greg's suggestion:

did solve it!
Thanks for the help all of you..
Steffen
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1327 times.
Similar Threads
JTextArea & Cursor
i need to position my Caret
how to get the info from a jtextarea
Issues with JTextArea as cellEditor of JTable Column.
how to auto scroll to see the bottom of the jtextarea?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:37:02.