默认关闭操作不会更改任何内容



>我正在使用 JFreeChart 库。饼图是应用程序的一小部分,我希望能够调用饼图,关闭它,然后继续使用该应用程序。但是,现在无论我选择哪个WindowConstants.X_ON_CLOSE选项,它都会关闭整个过程:

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

找到了一个解决方案,如果我通过JFrame而不是ApplicationFrame扩展类,工作正常。WindowConstants.DO_NOTHING_ON_CLOSE也是不正确的,需要WindowConstants.HIDE_ON_CLOSE来隐藏窗口而不停止应用程序。

希望这对其他人有所帮助!

相关内容

最新更新