Closing jfreechart swing window closing down the whole application
Asked Answered
G

2

5

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.

Groth answered 21/6, 2011 at 20:38 Comment(3)
Also no luck with HIDE_ON_CLOSE..Groth
You mean setDefaultCloseOperation(...DISPOSE...), right?Daviddavida
DISPOSE_ON_CLOSE and HIDE_ON_CLOSE both are working fine with JFrame which was non responsive for ApplicationFrame.Groth
P
12

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.

Phyllys answered 21/6, 2011 at 21:11 Comment(1)
I have removed ApplicationFrame and replaced with JFrame and its working fine.Groth
P
-1

Instead of

public class LineChart_AWT extends ApplicationFrame ,

public class LineChart_AWT extends JFrame is working fine.

Pharisee answered 19/4, 2016 at 21:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.