Forums Register Login

Scroll bar does not retain its position after or before pack

+Pie Number of slices to send: Send
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.....
+Pie Number of slices to send: Send
it would have been better had you posted in your other thread, instead of
creating a new one
https://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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi
Even if I set the value after pack(),it is resetting to 0th position.
Kinldy help me.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
I am using Border Layout......
+Pie Number of slices to send: Send
I tried it with BorderLayout and I still cannot reproduce your problem. Any chance you could post more code?
+Pie Number of slices to send: Send
Hi
Regarding scroll bar problem....
I have sent you private message.
kindly make a note of it.
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
Hi Angelin,

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



Darrin
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3577 times.
Similar Threads
ScrollPane oversized for JTable
Scroll in viewport when mouse is over a Popup?
Internet Explorer Scroll bar
Positioning scroll bar
problem with setting scrollbar value
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:17:35.