I'm trying to learn how to size a chart, so I trimmed the demo program to the bare bones (see below) and set the size of the chart panel to a specific size, but that doesn't work! The chart always fills up the entire frame. What am I doing wrong? I tried setBounds() as well. Thanks, -jbk
-----
public class JFreeChartDemo extends JFrame {
public JFreeChartDemo() {
this.setSize(800, 600);
SampleXYDataSource data = new SampleXYDataSource();
JFreeChart chart = JFreeChart.createXYChart(data);
JFreeChartPanel chartPanel = new JFreeChartPanel(chart);
chartPanel.setSize(500, 400);
getContentPane().add(chartPanel);
}
public static void main(String[] args) {
JFreeChartDemo f = new JFreeChartDemo();
f.show();
}
}
newbie Q on chart size
RE: newbie Q on chart size
Hi John,
The JFreeChartPanel size is controlled by the layout manager for the frame in the demo application. Your call to setSize() won't remain in effect for long, because the layout manager will make it's own call to setSize() when displaying the frame.
So to solve your problem, you need to read up on Layout Managers and find one that suits your requirement. It's time well spent, because you can't do much GUI development in Java without understanding how layout managers work.
Regards,
DG.
The JFreeChartPanel size is controlled by the layout manager for the frame in the demo application. Your call to setSize() won't remain in effect for long, because the layout manager will make it's own call to setSize() when displaying the frame.
So to solve your problem, you need to read up on Layout Managers and find one that suits your requirement. It's time well spent, because you can't do much GUI development in Java without understanding how layout managers work.
Regards,
DG.