开发者

JSlider sliding direction

i would like to know if it is possible to know on which side of the slider the thumb is moving. I have to implement a zoom function based on a slider and i can zoom in, but not zoom out.

if (!zoomSlider.getValueIsAdjusting()) {
            double minY = model.getMinY();
            double maxY = model.getMaxY();

            double distanceY = maxY - minY;

            double posY = minY + distanceY / 2.0;

    if(?) {
            distanceY /= zoomSlider.getValue();
    } else {
    distanc开发者_Go百科eY *= zoomSlider.getValue();
    }

            minY = posY - distanceY / 2.0;
            maxY = posY + distanceY / 2.0;

            changeMaxY(maxY);
    changeMinY(minY);
        }

Thank you.


I want to multiply by 1, 2, 3, or 4 when i go right and divide by 1, 2, 3, or 4 when i move left.

Keep track of the "previous" slider value so you can compare it to the "current" slider value. When the value increases your multiply, when it decreases you divide.


I think I know what you want. A slider with the thumb in the middle, and when sliding left or right it is zooming until you release the mouse.

If so, ou should set a maximum to your slider, like 9. Then, in your loop (I guess you are in a loop, otherwise you create a mouserelease event handler), you always set the value to 5. When sliding, you take the current value and subtract 5 from it. Now the result of that subtraction should represent the speed of your zooming. 0 means, no zooming. Everything positive means zooming in and everything negative means zooming out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜