jfreechart close my application main window

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Payam

jfreechart close my application main window

Post by Payam » Wed Aug 21, 2002 1:05 pm

Hi,

I'm using JFreeReport in my application. I shows a special chart during my program run time.

The problem is: When I close the chart window (JfreeCharts' window), it closes my main program window also. (The program main window have been made with JFRame).

How can I control the close command on my chart window (jfreechart's produced window).

Thanks in advence,
Payam

here is the code:

........
rs = exploreDB ("SELECT * FROM myTable");
Pie3DChart demo = new Pie3DChart("Test");
demo.Pie3DChartPreview(chartTitle,rs);
demo.pack();
demo.setVisible(true);
..
...

---------------------------
and the Class Declaration:


public class Pie3DChart extends ApplicationFrame {

/**
* Default constructor.
*/
public Pie3DChart(String title) {

super(title);
}

public void Pie3DChartPreview(String title,ResultSet rs) {

//int i=0;
boolean more;

// create a dataset...
DefaultPieDataset data = new DefaultPieDataset();
try {

more = rs.next();
if (!more) {

System.out.println("No rows found.");
return;
}
// Loop through the rows retrieved from the query
while (more) {
data.setValue(rs.getString(1), new Double(rs.getDouble(2)));
//i++;
rs.next();
}
}
catch (SQLException e) {
System.out.println(" results where found.");
}

// create the chart...
JFreeChart chart = ChartFactory.createPie3DChart(title, // chart title
data, // data
true // include legend
);

// set the background color for the chart...
chart.setBackgroundPaint(Color.lightGray);

// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
this.setContentPane(chartPanel);

}

Wolfgang Lenhard

Re: jfreechart close my application main window

Post by Wolfgang Lenhard » Wed Aug 21, 2002 2:10 pm

First I had the same problem.
I just changed
public class Chart extends AplicationFrame
into

Wolfgang Lenhard

Re: jfreechart close my application main window

Post by Wolfgang Lenhard » Wed Aug 21, 2002 2:12 pm

(sorry, i hit the post-button accidantly)

...
into
public class Chart extends JFrame

and in th chart-class-method

this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

Now, everything should work fine.

David Gilbert

Re: jfreechart close my application main window

Post by David Gilbert » Wed Aug 21, 2002 2:14 pm

Most of the demo applications extend ApplicationFrame to provide the behaviour of closing down completely upon exit. It is not intended that you use ApplicatioFrame within your own applications, just create a ChartPanel and add it to whatever container you want to use.

Regards,

DG.

Payam

Re: jfreechart close my application main window

Post by Payam » Wed Aug 21, 2002 7:11 pm

Thanks a lot,
Payam

Locked