Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable zoom by mouse dragged without disabling by mousewheellistener in jfreechart?

I would like to disable zooming by mouse dragging(which paints that rectangle), but not disable zooming by MouseWheel. I found in another topic how to disable zoom reset while dragging mouse to left (restoreAutoBounds) and I'm interested in how to solve this problem. Is there a little shortcut to do that?

like image 518
Bernard Burn Avatar asked Oct 07 '22 14:10

Bernard Burn


2 Answers

Ok, I've done it, by overriding MouseWheelListener. After chartPannel.setMouseZoomable(false).:

chartPanel.addMouseWheelListener(new MouseWheelListener() {
        public void mouseWheelMoved(MouseWheelEvent arg0) {
            if (arg0.getWheelRotation() > 0) {
                chartPanel.zoomOutDomain(0.5, 0.5);
            } else if (arg0.getWheelRotation() < 0) {
                chartPanel.zoomInDomain(1.5, 1.5);
            }
        }
    });

zoom(In/Out)Domain, because I wanted to rescale only domain axis.

like image 140
Bernard Burn Avatar answered Oct 10 '22 10:10

Bernard Burn


The mouse wheel listener implementation in the previous answer removes the zoom animation and does not zoom from the current mouse position. I found a workaround by hidding the rectangle using a transparent paint:

chartPanel.setZoomTriggerDistance(Integer.MAX_VALUE);
chartPanel.setFillZoomRectangle(false);
chartPanel.setZoomOutlinePaint(new Color(0f, 0f, 0f, 0f));
like image 41
JDM Avatar answered Oct 10 '22 11:10

JDM