This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How align a knob in a JScrollPane -> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How align a knob in a JScrollPane ->" Watch "How align a knob in a JScrollPane ->" New topic

How align a knob in a JScrollPane ->

Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
I have put a JPanel inside a JScrollPane. What happens when I open the frame is that the knob(slider) in the scroll pane is set to the middle of the track, which means that instead of seeing the header of my panel the first thing you see is the middle of the panel. The reason for this seams to be that I have used the escape sequence \n inside the panel.
I thought there might be some method called something like setInitialKnobX(int i), but after searching through the JScrollPane API several times I have found nothing what so ever!
Do you understand my problem, if so please help me out!
Dominic Steng�rd
Sun Certified Java 2 Programmer
[This message has been edited by Dominic Steng�rd (edited February 08, 2001).]

Dominic Steng�rd<br />Sun Certified Java 2 Programmer

Joined: Feb 07, 2001
Posts: 2
I am also facing the similiar problem. I have also taken the instance of scrollbar from the view of scroll pane. there exist methods for setting the nob for a scrollbar such as setValue(int). But in case of JScrollPane these methods are not working.
In your case also there may be chance that when you will take instance of JScrollBar from JViewPort of JScrollPane, then you can set its value.
Dominic Steng�rd
Ranch Hand

Joined: Feb 05, 2001
Posts: 186
Hi, I still have the problem listed above...
Could someone please help me out!
Thanks in advance!
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
I think you need to deal with the viewport. Try
yourScrollPane.getViewPort.reshape(int x,int y,int w,int h)
where x and y =0 should move the view to the upper left corner of your panel
or maybe
yourScrollPane.getViewPort.setViewPosition(new Point(0,0))
the viewport should take care of moving the scrollbars for you.
Good Luck!
Ron Lewis

Joined: Jul 08, 2004
Posts: 2
This didn't work for me with a JScrollPane
I agree. Here's the link:
subject: How align a knob in a JScrollPane ->
Similar Threads
Passed by the skin of my teeth
Scored 93%
How to read properties files from outside Container?
Thanks Every One!!!
Second time answer please 3Drect