File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Scroll bar does not retain its position after or before pack Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Scroll bar does not retain its position after or before pack " Watch "Scroll bar does not retain its position after or before pack " New topic
Author

Scroll bar does not retain its position after or before pack

angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
Hi
My Scroll bar does not retain its position after pack in my application.
But i need to retain its state.
My code snippet is :

System.out.println("VAlue--->" + getHXValue());
scrollPane.getHorizontalScrollBar().setValue(getHXValue());
pack();

My VAlue printed is 100.
But my positon of scroll bar is at 0 th location.
Can any one help me.....
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
it would have been better had you posted in your other thread, instead of
creating a new one
http://www.coderanch.com/t/344899/GUI/java/scroll-bar

anyway, it works OK for me, so the problem must be with some other part of
your code.

post a sample program that demonstrates the problem
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
I could not post my entire code. I am having my code in framework.
I am working in a project. In that I am facing this difficulty.could you please send me your sample code.
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
Hi All,
My code is:
scrollPane.getHorizontalScrollBar().setValue(100);
//pack();
log.debug("Value------>" + scrollPane.getHorizontalScrollBar().getValue());

Initially my horizontal scroll bar position is 0.
Then i am am hardcoding it to 100.
But now my scroll bar position is at 90.
Value--------->90
I don't know why???
If i am setting the value below 90 it works well.
But i crossed above 90, whatever the value it is retaining to 90.
This works welll only if there is no pack().
If i use pack(), my scroll bar positioned to 0.
Can anybody help me to get rid of this problem.
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Hi Angelin,

Try the following line:

scrollPane.getHorizontalScrollBar().setVisibleAmount(0);

<Edit>
I forgot to mention, the correct way would be to access the value like so:

[ June 28, 2007: Message edited by: Darrin Cartwright ]

Life is good on the Ponderosa,<br />but mind where you step.
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
Hi All,
I used


By this snippets its retaining the positon very well.
I got what i expected.Thanks for providing me the solution.
But if I use the code provided below,


My scroll bar is not retaining its position.
The problem here is,
assume my getHXValue() is 100.I am setting this to my horizontal scroll bar.
But when i retrieve the value of horizontzl scroll bar it is 0.
LLLLL------>0 ( because of pack()).
But i need to use pack() and also retain the position of scroll bar.
Have you got the point?
Kindly reply me.
Thanks
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
HI Angelin,

You need to save the position of the ScrollBar and restore it after calling pack(). If you are just setting it to the value of getHXValue() after calling pack(), just call the set line again after pack:


Good luck!

Darrin
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
Hi
Even if I set the value after pack(),it is resetting to 0th position.
Kinldy help me.
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Hi Angelin,

I'm sorry, but I cannot repeat your exact problem, It works fine for me. What LayoutManager are you using to control the position of the JScrollBar?
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
I am using Border Layout......
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
I tried it with BorderLayout and I still cannot reproduce your problem. Any chance you could post more code?
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25
Hi
Regarding scroll bar problem....
I have sent you private message.
kindly make a note of it.
angelin prema
Greenhorn

Joined: Jun 11, 2007
Posts: 25

ouput :
hx : 347
Hori : 347
VY :132
Verti :132
VY :132
vertical height :502
But my scrollbar postion is not retaining? It is restting to 0.
please reply me
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
Hi Angelin,

Just a guess, but change the following line and see if it helps:



Darrin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scroll bar does not retain its position after or before pack