Scroll bar does not retain its position after or before pack

Hi All,

I used

log.debug("VAlue>" + getHXValue());

scrollPane.getHorizontalScrollBar().setVisibleAmount(0);

scrollPane.getHorizontalScrollBar().setValue(scrollPane.getHorizontalScrollBar().getMaximum());

scrollPane.getHorizontalScrollBar().setValue(getHXValue());

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,

log.debug("VAlue>" + getHXValue());

scrollPane.getHorizontalScrollBar().setVisibleAmount(0);

scrollPane.getHorizontalScrollBar().setValue(scrollPane.getHorizontalScrollBar().getMaximum());

scrollPane.getHorizontalScrollBar().setValue(getHXValue());

pack();

log.debug("LLLLL>" + scrollPane.getHorizontalScrollBar().getValue());

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

[1340 byte] By [rose@rosea] at [2007-11-27 9:12:36]
# 1
just call getvalue to store the value, pack, and then use setvalue to put it back to the original value
calvino_inda at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 2
Sorry,I didn't get you.Can you send me in the form of code.Thankyou
rose@rosea at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 3

log.debug("VAlue>" + getHXValue());

scrollPane.getHorizontalScrollBar().setVisibleAmount(0);

scrollPane.getHorizontalScrollBar().setValue(scrollPane.getHorizontalScrollBar().getMaximum());

scrollPane.getHorizontalScrollBar().setValue(getHXValue());

int formerValue = getHXValue();

pack();

scrollPane.getHorizontalScrollBar().setValue(formerValue);

log.debug("LLLLL>" + scrollPane.getHorizontalScrollBar().getValue());

calvino_inda at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 4
HiAgain it is initialising to 0.VAlue>83LLLLL>0
rose@rosea at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 5

try the following code:

log.debug("BEFORE>" + getHXValue());

JScrollBar hor = scrollPane.getHorizontalScrollBar();

hor.setValue(getHXValue());

int formerValue = getHXValue();

pack();

log.debug("BETWEEN-->"+formerValue);

hor.setValue(formerValue);

log.debug("AFTER>" + hor.getValue());

if the "before" and "after" value aren't the same, it means there is something ****** up somewhere else in the code

but i wonder if when you pack, the value you try to reach does exist any more, since the pack may reduce scrollbar height

if this "before" value is more than scrollbar height after pack, then the scrollbar value might comes back to 0

calvino_inda at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 6
Hi,I got like this,Before-->120,Between>120After->0What does it mean?How can i rectify this?With out pack(),it retains the position well.
rose@rosea at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...
# 7

well in this case, i'm not sure, but it may come from what i told you earlier

here is an example to illustrate my explanation:

Let's say before pack(), your scrollbar can be a value between "0 and 160", and it's set on "120"

Once you pack, the scrollbar height changes ; as a consequence, the range of value is not "0 to 160" any more but "0 to 110" (for example)

When you try to assign the value "120" to the bar, it's not in the new range so JVM doesn't agree the instruction, and scrollbar goes back to "0"

i'm really not sure of what i say, it's just a supposition (i have to way to test it right now), but i don't really see what else could make this bug occur

calvino_inda at 2007-7-12 21:59:17 > top of Java-index,Java Essentials,Java Programming...