默认关闭操作没有改变
Default Close Operation Changing Nothing
我正在使用 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);
}
找到了一个解决方案,如果我将 class 扩展 JFrame
而不是 ApplicationFrame
,则工作正常。另外 WindowConstants.DO_NOTHING_ON_CLOSE
不正确,需要 WindowConstants.HIDE_ON_CLOSE
在不停止应用程序的情况下隐藏 window。
希望这对其他人有帮助!
我正在使用 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);
}
找到了一个解决方案,如果我将 class 扩展 JFrame
而不是 ApplicationFrame
,则工作正常。另外 WindowConstants.DO_NOTHING_ON_CLOSE
不正确,需要 WindowConstants.HIDE_ON_CLOSE
在不停止应用程序的情况下隐藏 window。
希望这对其他人有帮助!