How to Resize a JFreeChart
Adding a JFreeChart to a JPanel can result in an oversized display. To address this issue, there are several options available.
When creating the ChartPanel, you can:
To calculate the size dynamically, you can override getPreferredSize():
@Override public Dimension getPreferredSize() { // given some values of w & h return new Dimension(w, h); }
Additionally, the layout of the container containing the ChartPanel can influence its size. The default layout for JPanel is FlowLayout, while that for JFrame is BorderLayout. For example, ThermometerDemo uses both preferred values in the constructor and a GridLayout to enable dynamic resizing.
[Image of ThermometerDemo displaying both preferred values in the constructor and a GridLayout]
The above is the detailed content of How Can I Resize a JFreeChart to Fit My JPanel?. For more information, please follow other related articles on the PHP Chinese website!