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
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
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
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.