Here is my problem : I have a JTabbedPane with two tabs which have the same structure : a Jtable and under a JFreeChart (from XYDataset). The JTable are different but I'd like to have the same chart on the two tabs.
I implemented the Cloneable interface to do it, and I have my chart on both tabs, but there's something strange : the event on the second chart doesn't work. For example, if I try to select a rectangular zone for zooming on the chart on the second tab, the selection rectangle still stays but nothing happens. If I go on the first chart, the zoom has be done on it. If I go back to the second chart, the chart has been updated and the zoom is correct. If I first zoom on the first chart, and then I go to the second tab, the zoom has been done too.
It seems to me there must be a problem of refreshing the chart, but I'm very surprised with the zoom or right click function not working at first on the second chart, but working if I go to first tab and then back to the second.
Thanks for helping.
Copy of a chart : problem of refreshing ?
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Have you cloned the JFreeChart instance? Or the ChartPanel? It sounds like you've found a bug, so if you give me some more hints about how to reproduce it, I'll track it down.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


In fact, I put the chart in a JPanel and I'm cloning this JPanel. I have to say I'm not sure I perfectly cloned the JPanel. I show you the concerned part of the code :
Code: Select all
public class WinSDF extends JPanel implements Cloneable {
private XYDataset data = GenerateSDF.createDataset();
private static int num;
private GraphieSDF chart;
private ChartPanel panel;
protected static JFreeChart graphie1;
public WinSDF()
{
chart = new GraphieSDF();
graphie1 = chart.createPointChart(data);
panel = new ChartPanel(graphie1, true, true, true, true, true);
panel.setPreferredSize(new java.awt.Dimension(500, 400));
panel.addChartMouseListener(new ChartMouseListener(){
...
}
public void chartMouseMoved(ChartMouseEvent event) {
...
}
});
this.add(panel);
this.setEnabled(true);
}
@Override
protected Object clone() throws CloneNotSupportedException {
WinSDF clone = (WinSDF) super.clone();
clone.data = this.data;
clone.chart = this.chart;
clone.graphie1 = this.graphie1;
clone.panel = this.panel;
panel.addChartMouseListener(new ChartMouseListener(){
...
});
this.add(panel);
this.setEnabled(true);
return clone;
}
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Any reason why graphie1 is static?
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
But you know that a static field is shared by all instances of the same class, right? So this could be the problem with your cloning.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

