I am using Netbeans GUI builder to put a panel in a Jframe, where the size of the panel is set by me in the GUI builder. I'd like to embed a chart into this panel. Using answers from previous SO threads, I can achieve this behavior as follows:
ChartPanel p = new ChartPanel(chart);
jPanel1.setLayout(new java.awt.BorderLayout());
jPanel1.setPreferredSize(new Dimension(400, 200));
jPanel1.add(p, BorderLayout.CENTER);
jPanel1.validate();
Where I used setPreferredSize
as a way to change the plot size. Otherwise, my plot is huge compared to the actual size I set on the panel. How can I have setPreferredSize
infer the correct size from the panel dimension as created in the netbeans GUI? Right now, I have to manually pass a Dimension
, which needs tuned each time I mess with the UI.
Thanks