Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing jfreechart swing window closing down the whole application

I have integrated this Jfreechart Bar Demo with my swing application. I have put the following code in the action performed method of a button, this code was previously in the main method of the Bar Demo class.

final BarChart3DDemo3 demo = new BarChart3DDemo3("3D Bar Chart Demo 3");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

This is generating the Bar Chart. But on closing the Bar chart Window. My Whole application is getting closed.

I have tried to insert demo.getDefaultCloseOperation(ApplicationFrame.DISPOSE_ON_CLOSE); but its not working. Although not giving any error.

I have also tried to insert this in the BarChart3DDemo3 constructor but its giving error getDefaultCloseOperation() method does not take int argument.

I have no clue what to do next? Please help. Thanks.

like image 312
JavaBits Avatar asked Jun 21 '11 20:06

JavaBits


1 Answers

Note that ApplicationFrame "listens for window closing events, and responds by shutting down the JVM." It's intended for demo applications. Instead, put your ChartPanel in a JFrame, as shown here.

like image 50
trashgod Avatar answered Nov 15 '22 10:11

trashgod