• 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

Java stop JScrollPane auto scrolling back to the top when JTextArea is updated

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a swing application that gets football scores from a website using Jsoup.

When the "Get Scores" button is pressed, the scores are printed to a JTextArea with a JScrollPane.

I have also used a SwingWorker to update the scores every couple of seconds.

My problem is that every time the JTextArea updates, the JScrollPane scrolls back to the top of the text area. I wan the scroll bar to stay where the user left it.

Here is my code (The update is currently set to update every 1 second so you can see what the scroll bar is like).



and here is the main:


Can anyone help?

Thanks.
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
search for DefaultCaret.ALWAYS_UPDATE
 
Matt Hughes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

m Korbel wrote:search for DefaultCaret.ALWAYS_UPDATE



Hi,

I already tried that but it does not work.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a link to another Ranch thread with a similar (but opposite) problem. Perhaps the method mentioned there would fix your problem...

https://coderanch.com/t/562291/GUI/java/set-caret-position-beginning-JtextArea
 
Matt Hughes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Here's a link to another Ranch thread with a similar (but opposite) problem. Perhaps the method mentioned there would fix your problem...

https://coderanch.com/t/562291/GUI/java/set-caret-position-beginning-JtextArea



Hi,

That doesn't work either.

I tried this:



and setting the caret position, but it still does not do what i want it to.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So let's see your SSCCE (<-- follow that link) where you use that method unsuccessfully, and we can go from there. "Doesn't work" isn't really a fruitful basis for discussion in this kind of forum.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wan the scroll bar to stay where the user left it.



Check out Smart Scrolling. If the scrollbar is at the bottom, then it will automatically scroll as new data is added. If the user has moved the scrollbar somewhere else then it will stay there as new data is added.
 
reply
    Bookmark Topic Watch Topic
  • New Topic