我有一个主 JFrame,其中包含用于不同功能的各种面板,人们可以在其中进行计算。我想在用户点击第一个计算按钮时打开一个新的 JFrame 并用作输出窗口(如果您熟悉它们,则类似于 SPSS 输出窗口)。
新的 JFrame 将完全独立,并将有自己的菜单栏……简单的 JDialog 不适合这里。
最佳答案
- 无法抗拒,简单的不同意答案
JFrame frame = new JFrame(
);和frame.setVisible(true);
I want to open a new JFrame when the user hits the first calculate button and serve as a Output window (Simlar to SPSS output windows if you are familiar with them).
don't do that, create only two JFrames ,重复使用第 2 次。
JFrame
通过使用getContentPane.removeAll()
,用于JButton
的另一个操作
那么所有的生命周期将只关于
setVisible(true)
/setVisible(false)
将
DefaultCloseOperations
更改为HIDE_ON_CLOSE
The New JFrame will be completely separate and will have its own menu bar. A simple JDialog is not the way to go here.
JDialog
有什么问题,Toolbar
中只有一个按钮,而JFrame
中只有一个按钮,简单的不同意,
Output window (Simlar to SPSS output windows if you are familiar with them).
- 使用
SwingWorker
或Runnable#Thread
(需要包装到invokeLater
中)获取放置在 JDialog 中的 JComponents 的值,如果所有更改都已完成调用包裹在invokeLater()
中的
JDialog.setVisible(true)
关于java - 打开一个新的 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15167404/