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

自古美人都是妖i 提交于 2019-12-01 18:02:20

问题


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?


回答1:


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.




回答2:


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));


来源:https://stackoverflow.com/questions/12511210/how-to-disable-zoom-by-mouse-dragged-without-disabling-by-mousewheellistener-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!