I just found that when i add a ChartPanel to a JFrame, the ChartPanel will resize to fit the frame as the JFrame dragged larger or smaller. However, when i add the ChartPane
Try my code and it works fine.
Note that :
I have one frame which contains a panelMain, A panelMain contains a subPanel and a subPanel contains ChartPanel.
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
JPanel panelMain = new JPanel(new GridLayout(0,2));
ChartPanel chartPanel = createChart();
JPanel subPanel = new JPanel(new BorderLayout());
subPanel.setBorder(BorderFactory.createTitledBorder("Consommation"));
subPanel.setPreferredSize(new Dimension(400, 200));
subPanel.add(chartPanel);
panelMain.add(subPanel);
frame.add(panelMain);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
And now when you resize your window application. Your chartPanel will resized automatically. Hope this helps.