How to use mouse wheel to zoom in(out) ?
Posted: Thu Nov 08, 2007 3:10 am
Hi:
JFreeChart default to zoom in(out) when the mouse is dragged, but I want to use mouse wheel to control this, so I read the source code of ChartPanel class, and copyed some methods to my class,there are
getScreenDataArea()
translateScreenToJava2D(Point screenPoint)
zoomInBoth(double x, double y)
zoomInDomain(double x, double y)
zoomInRange(double x, double y)
zoomOutBoth(double x, double y)
zoomOutDomain(double x, double y)
zoomOutRange(double x, double y)
Then I add MouseWheelListener to the panel, write class mouseWheelHandle to handle the event
But it didn't work!
I don't know what to do next, would someone give me some help?
JFreeChart default to zoom in(out) when the mouse is dragged, but I want to use mouse wheel to control this, so I read the source code of ChartPanel class, and copyed some methods to my class,there are
getScreenDataArea()
translateScreenToJava2D(Point screenPoint)
zoomInBoth(double x, double y)
zoomInDomain(double x, double y)
zoomInRange(double x, double y)
zoomOutBoth(double x, double y)
zoomOutDomain(double x, double y)
zoomOutRange(double x, double y)
Then I add MouseWheelListener to the panel, write class mouseWheelHandle to handle the event
Code: Select all
private class mouseWheelHandle implements MouseWheelListener
{
public void mouseWheelMoved(MouseWheelEvent e)
{
zoomPoint=e.getPoint();
if(e.getWheelRotation()>0){
zoomInBoth(zoomPoint.getX(), zoomPoint.getY());}
else if(e.getWheelRotation()<0){
zoomOutBoth(zoomPoint.getX(), zoomPoint.getY());
}
}
I don't know what to do next, would someone give me some help?