简体   繁体   English

如何在jfreechart中通过鼠标拖动禁用缩放而不用mousewheellistener禁用缩放?

[英]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. 我想通过鼠标拖动禁用缩放(绘制该矩形),但不希望通过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. 我在另一个主题中找到了如何在向左拖动鼠标(restoreAutoBounds)时禁用缩放重置,并且我对如何解决此问题感兴趣。 Is there a little shortcut to do that? 有一些捷径可以做到吗?

Ok, I've done it, by overriding MouseWheelListener. 好的,我通过重写MouseWheelListener做到了。 After chartPannel.setMouseZoomable(false).: 在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. zoom(In / Out)Domain,因为我只想重新缩放域轴。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM