Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programmatically set the knob position of a JScrollBar

 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If someone achieve this, please, for God sake, post the code here.

[ EJFH: No profanity, please. ]
[ December 19, 2004: Message edited by: Ernest Friedman-Hill ]
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot: I'm referring to the JScrollBar of a JScrollPane.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

where value is an int between min and max.
An example.
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer... but, well, I forgot to mention it, but: I need to adjust the knob position OUTSIDE a adjustementListener. I need to do something like this:

int oldValue = scrollPagina.getVerticalScrollBar().getModel().getValue();

//after some operations that change the knob position... (selecting text, etc.)

scrollPagina.getVerticalScrollBar().getModel().setValue(oldValue);


This doesn't work. ONLY inside the listener... someonde could explain this behaviour? And what can I do?

Thanks.
 
Jeronimo Backes
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... Only after I solved the problem (with a crazy solution) I realized that the issue were that Java was doing "something" behind the scenes... and changing the caret position after the method was called (reseting my changes)

But a better solution (much better than the one I've invented) is to create a Thread, calling a short sleep:



So, when it's time to put the knob back, it's just write:


Finally!! I can rest in peace! (and in pieces)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic