Search code examples
javajfreechart

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?


Solution

  • 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.