I've tried looking for answers to get this but it didn't work properly so here goes my question. I have created a barchart and I want to add this to a jpanel in a java swing application , here is my code for adding chart to the panel,
void addpanel(JFreeChart chart) {
ChartPanel chartpanel = new ChartPanel(chart);
jPanel2.setLayout(new BorderLayout());
jPanel2.add(chartpanel, BorderLayout.CENTER);
chartpanel.setVisible(true);
this.add(jPanel2);
this.pack();
setContentPane(jPanel2);
jPanel2.setVisible(true);
}
but when I run this , chart is not visible in the jpanel2 and it don't give any errors. How can I change this code to make it work ?