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]
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3