Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What causes the refresh?  RSS feed

 
Rebecca Witmer
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) {
htmlView.getVerticalScrollBar().setValue(0);
}

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

Baffledly,
Rebecca
 
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!