newbie Q on chart size

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
John Kim

newbie Q on chart size

Post by John Kim » Fri Aug 25, 2000 6:14 pm

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();
}
}

David Gilbert

RE: newbie Q on chart size

Post by David Gilbert » Mon Aug 28, 2000 1:24 am

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.

Post Reply