I'm a beginner in JavaSwing and JFreeChart. I have done an XYLineChart and I have add a scrollbar to this chart. I have done an SlidingXYDataset class like a SlidingCategoryDataset for my XYLineChart. And then my scrollbar works. This is the code:
JScrollBar scroller = new JScrollBar(JScrollBar.HORIZONTAL, 0, 10, 0, 20);
@Override
public void stateChanged(ChangeEvent e) {
int value = scroller.getValue();
dataset.setFirstItemIndex(value);
}
And now, I don't know how to adapt this scrollbar when I use the zoom. For my zoom, I have a button with an ActionListener. When I push the button, it triggers this code (in the constructor of my panel, the setMouseZoomable is false):
public class ZoomListener extends MouseAdapter{
private SpectrumPanel specPanel;
private SpectrumController control;
private ChartPanel panel;
private JFreeChart chart;
public ZoomListener(SpectrumController c){
control = c;
specPanel = c.getSpectrumPanel();
panel = c.getSpectrumChartPanel().getChartPanel();
chart = c.getSpectrumChartPanel().getChartPanel().getChart();
}
@Override
public void mousePressed(MouseEvent e) {
panel.setMouseZoomable(true);
}
@Override
public void mouseExited(MouseEvent e) {
panel.removeMouseListener(this);
panel.setMouseZoomable(false);
panel.setHorizontalAxisTrace(false);
panel.setVerticalAxisTrace(false);
specPanel.getGraphPanel().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
If you have ideas to link my scrollbar to the zoom, I'll take it with pleasure. Thank you for your help.