this being my first question on Stack Overflow, I apologize for any mistakes in describing the problem, so feel free to ask for more or a different description.
I am making a program with the jFreeChart API where I'm trying to allow for live editing of displayed charts by creating a ChartPanel and refreshing the chart inside it each time an edit is made.
public void displayChart(JFreeChart chart) {
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setDomainZoomable(true);
chartPanel.setVisible(true);
jPanel3.add(chartPanel, BorderLayout.CENTER);
jPanel3.setLayout(new java.awt.BorderLayout());
jPanel3.validate();
}
private void ChartSelectionActionPerformed(java.awt.event.ActionEvent evt) {
String selection;
selection = ChartSelection.getActionCommand();
if (selection == "S/D") {
Chart Chart = new Chart();
JFreeChart chart = Chart.generateSandDBase();
displayChart(chart);
} else {
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Series Series = new Series();
Chart Chart = new Chart();
XYSeries supply = Series.getSupplySeries();
double tempX;
double tempY;
for (int i = 0; i < 10; i++) {
tempX = (double) supply.getX(i);
tempX = tempX + 1;
tempY = (double) supply.getY(i);
supply.remove(i);
supply.add(tempX, tempY);
System.out.println(supply.getX(i).toString());
System.out.println(supply.getY(i).toString());
}
Series.setSupplySeries(supply);
JFreeChart chart = Chart.generateSandD(supply, Series.getDemandSeries());
displayChart(chart);
}
I have found similar questions asked but all of the solutions I have found haven't worked in solving this issue. At runtime, the chart simply doesn't appear in the panel. I have tried adding a new panel inside the existing one, then adding the ChartPanel inside that. I have tried validating the entire JFrame, and also scrubbing the Jpanel before adding my ChartPanel, and then validating all of it after that.
I am a little worried that this might have something to do with Matisse, as I am using NetBeans' GUI builder which seems to run on some dark space magic that could be screwing this all up.
Thanks so much for any help, I am a novice programmer, so it all goes a really long way.
Edit: So, after a few more hours of messing around with everything, I heard something about violating hierarchy when I try to add a chart at runtime. I don't know very much about this. Is there a way for me to instantiate my ChartFrame in the GUI constructor? I know where to put the code, but I can't seem to get this working as a chart frame must have a chart to be instantiated.