*
The moose likes Swing / AWT / SWT and the fly likes Programmatically set the knob position of a JScrollBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Programmatically set the knob position of a JScrollBar" Watch "Programmatically set the knob position of a JScrollBar" New topic
Author

Programmatically set the knob position of a JScrollBar

Jeronimo Backes
Greenhorn

Joined: Sep 20, 2004
Posts: 29
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 ]

The art of being crazy is to NEVER commit the crazyness of being normal.
Jeronimo Backes
Greenhorn

Joined: Sep 20, 2004
Posts: 29
Sorry, I forgot: I'm referring to the JScrollBar of a JScrollPane.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535

where value is an int between min and max.
An example.
Jeronimo Backes
Greenhorn

Joined: Sep 20, 2004
Posts: 29
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

Joined: Sep 20, 2004
Posts: 29
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Programmatically set the knob position of a JScrollBar