• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scroll bar does not retain its position after or before pack

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
angelin prema
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
angelin prema
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Even if I set the value after pack(),it is resetting to 0th position.
Kinldy help me.
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Border Layout......
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it with BorderLayout and I still cannot reproduce your problem. Any chance you could post more code?
 
angelin prema
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Regarding scroll bar problem....
I have sent you private message.
kindly make a note of it.
 
angelin prema
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Angelin,

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



Darrin
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic