How to display a JFreeChart in a NetBeans project

后端 未结 1 1017
囚心锁ツ
囚心锁ツ 2021-01-13 00:01

This is similar to a question I asked yesterday but more specific to the problem. What is the correct method to add a JFreeChart to a NetBeans project which already contains

相关标签:
1条回答
  • 2021-01-13 00:19

    My updateChart() hides the entire JFrame.

    JFreeChart chart = createChart(dataset); 
    JPanel chartPanel = new ChartPanel(chart); 
    setContentPane(chartPanel); 
    

    That would be because you are replacing the content pane of your frame with the panel from free chart.

    I don't know what layout manager you are using, but you need to "ADD" the free chart panel to the panel that contains all the other components. So maybe when you design the general form in Netbeans you add an empty panel to the place where you want the free chart panel to be added. Then when you add the free chart panel the code would be something like:

    emptyFreeChartPanel.add( chartPanel );
    emptyFreeChartPanel.getParent().validate();
    

    The validate tells Swing that components have been added so the layout manager will be invoked.

    0 讨论(0)
提交回复
热议问题