View Full Version : Problem with a slider

25 Aug 2010, 3:40 AM

In my application, I have a Window in which I put a slider. I indicate a width for the slider when I construct it.

So, before I open my window, I set a minValue and a maxValue to te slider. After that, I use the setValue() property to indicate where the thumb must be positioned on the slider (the value indicated is between the minValue and the maxValue).

After this, I show the window which contains the slider. The first time I open the window, it works fine, but when I close the window and set the new properties (minValue, maxValue and setValue) before I want reopen it, I have a problem.

In fact, the minValue and the maxValue are set correctly. The value set (with the setValue() property) also seems to be correct (when I pass the mouse cursor over it, a tooltip with the correct value is shown). But, the real problem is that the thumb is always on the left of the slider (except the first time I open the window).

Can you help me ?


25 Aug 2010, 3:46 AM
Try setting the value after showing the window.

25 Aug 2010, 3:58 AM
I tried it, but the result is the same.

In fact, when I run my code in debug mode, I see a problem here (in Slider.class) :

protected double getRatio() {
int v = maxValue - minValue;
if (vertical) {
int h = innerEl.getHeight();
return v == 0 ? h : ((double) h / v);
} else {
int w = innerEl.getWidth();
return v == 0 ? w : ((double) w / v);
In the first case I described before, w has the correct value.
In the second case (when I want reopen my window) w has always a value of 0.

Why ?

25 Aug 2010, 4:06 AM
Because it is hidden. That is why i suggested to set the value after the window was shown.

25 Aug 2010, 4:14 AM
Finally it works fine with your solution (I made a stupid mistake in my copy/paste).

Thank you :)