Search code examples
javajfreechart

Default Close Operation Changing Nothing


I'm using the JFreeChart library. The pie chart is a small part of the application, and I'd like to be able to call up the pie chart, close it, and continue using the application. However, right now it closes the whole process, regardless of which WindowConstants.X_ON_CLOSE option I choose:

public PieChart(final List<Window> windows) {
    super("Kronos - Window Data");
    final JFreeChart chart = PieChart.createChart(windows);
    SwingUtilities.invokeLater(() -> {
        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        final int width = (int) screenSize.getWidth();
        final int height = (int) screenSize.getHeight();
        this.setSize(width, height);
        this.setLocationRelativeTo(null);
        super.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        // this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        this.setVisible(true);
    });
    final ChartPanel panel = new ChartPanel(chart);
    this.setContentPane(panel);
}

Solution

  • Found a solution, if I extend the class by JFrame rather than ApplicationFrame, works fine. Also WindowConstants.DO_NOTHING_ON_CLOSE was incorrect, needed WindowConstants.HIDE_ON_CLOSE to hide window without stopping the application.

    Hope this helps someone else!