user3435500
user3435500

Reputation: 5

Jbutton not performing intended function

When I click this button it is suppose to create a boxplot with whiskers but instead it just keeps generating the same page when it is clicked. When I placed this code in the constructor the boxplot is generated but I can't seem to get it working in a button. The function createDataset() just creates values for the boxplot.

private void generateActionPerformed(java.awt.event.ActionEvent evt) {                                         
BoxAndWhiskerXYDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
setContentPane(chartPanel);

BoxAndWhiskerChart demo = new BoxAndWhiskerChart();
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}                                        

Upvotes: 0

Views: 29

Answers (1)

ControlAltDel
ControlAltDel

Reputation: 35011

It's hard to tell what you're doing, but this in your button handler looks wrong

setContentPane(chartPanel);

Are you trying to set the contentPane of the current JFrame to this chartPanel? If so, what's the demo object after this about? Also, you need to call revalidate(); repaint(); to make this chart show up

Upvotes: 1

Related Questions