This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Srolling of JScrollBar without user involvement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Srolling of JScrollBar without user involvement" Watch "Srolling of JScrollBar without user involvement" New topic
Author

Srolling of JScrollBar without user involvement

Sriram Sankar
Greenhorn

Joined: Mar 01, 2001
Posts: 22
I have an application which i have put it on the jscrollpane, the problem is once i reach the bottom of the visible area in my application , i need my jscrollpane to scroll upwards automaticaly so that i need not every time manually scroll down to enter next set of data or view next set of data.
My requirement is to scroll the JScrollPane with code rrather that user involvement.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Sriram,
I point you to 2 items:
JScrollPane --> getVerticalScrollBar (getHorizontalScrollBar)
JScrollBar --> setValue
Regards,
Manfred.
Chris Robertson
Greenhorn

Joined: Sep 19, 2002
Posts: 3
I'm trying something similar and am in fact using the setValue method, it seems to work but then teh scroll pane just bounces back down to the bottom. Sort of frustrating. (ok very frustrating.)
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Try using the scrollRectToVisible( Rectangle ) method of JComponent on the component inside the scrollpane rather than trying to move the scrollpane programmatically through the scroll bar...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Haakon Lind
Greenhorn

Joined: Sep 18, 2002
Posts: 22
I know this is a gravedigg, but I have the same problem as described here. I have allready tested the solutions mentioned here, though and neither of them work.
To be more specific of the problem: I add text to the beginning of a JScrollPane. At one point, the scrollbar gets fixed at somewhat bellow middle, and I can`t seem to nod it up to the top by calling some legitimate methods (as mentioned here).

Please, I need some help from some swing dirty hands.
[ November 26, 2006: Message edited by: Haakon Lind ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if you have a textComponent in the scroll bar, the scroll will follow the caret,
so, when adding some text, include
textComponent.setCaretPosition(0);
Haakon Lind
Greenhorn

Joined: Sep 18, 2002
Posts: 22
Originally posted by Michael Dunn:
if you have a textComponent in the scroll bar, the scroll will follow the caret,
so, when adding some text, include
textComponent.setCaretPosition(0);


Great, this worked perfectly!
I`m used to getting a notification for answers, so I`m glad I checked back.
 
Don't get me started about those stupid light bulbs.
 
subject: Srolling of JScrollBar without user involvement