The first check box sets the scroll to 10. sp.getVerticalScrollBar().setValue(10);
The second check box reloads (ta.setText(text)) the text and then sets the scroll to 10.
Why does the second one not work?
I have attached a simple program. It is probably easier for you to compile and run than for me to go into detail explaining further.
Thanks in advance!
Peace,<br /> <br />Jeff
Joined: Feb 26, 2006
The Swing updates the UI related changes only once using the Event Dispatch Thread (EDT). The method
sp.getVerticalScrollBar().setValue(10); Does not update the UI. It is simply setting the value at 10. hence it is done immediately. The second method that add the text to the screen willbring the Scroll Pane down but this will not be done immediately. It will be done on the EDT. Hence when you run your code it will always run the setValue() method first and the setText() method later. Thus you will not see the effect of setValue().
The Solution would be to use SwingUtilities.invokeLater(). I have modified your code a little to make it more neater. Hope it help!!!