Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

What causes the refresh?

Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to figure out what would make a command work in one place but not in another. In my code I have a scrollPane initialized to hold some text.

After the code is first set up the scroll bar is at bottom. Then I have a listener that runs.

public void valueChanged(TreeSelectionEvent e) {

When you click on something all it does is run the stubborn command above. In the listener it works! What is going on?

Rebecca Witmer
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After five days of banging my head on this problem I have found somewhat of an answer. For some reason swing only wants to refresh the scrollbar if an event occurs. When someone clicked in my tree and event occurred and it was happy about running the setValue command to scroll the bar to the top. However, my ultimate goal was to change the text each time someone clicked in the tree, which would set the scroll bar back to the bottom. So I needed another type of event to occur that would not involve the user clicking. After all, what I am trying to avoid in the first place is making the user drag the scrollbar back to the top. So it occurred to me to do the following...

...and add a method like this.

If I ever want to put the scroll bar at the top I just call timer.start();. The setValue() method will run inside the event even though it won't other places. I hope that helps someone in the future. Does anybody with any better knowledge of the way this all work have an explanation as to why it behaves this way? Is it a bug in Swing?
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic