• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextArea scrolls to bottom

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Steffen Foldager
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call scrollRectToVisible( new Rectangle( 0, 0, 0, 0 ) ); on the actual Component you want to scroll, not on the JScrollPane...

-Nate
 
Steffen Foldager
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic