[英]Open a new JFrame
I have a main JFrame that has all kinds of panels in it for different functions and people can calculate things in them.我有一个主 JFrame,里面有各种各样的面板,用于不同的功能,人们可以在其中计算东西。 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).
我想在用户点击第一个计算按钮时打开一个新的 JFrame 并用作输出窗口(如果您熟悉它们,则类似于 SPSS 输出窗口)。
The New JFrame will be completely separate and will have its own menu bar ... A simple JDialog is not the way to go here. New JFrame 将是完全独立的,并且将拥有自己的菜单栏......一个简单的 JDialog 不是这里的方法。
JFrame frame = new JFrame(
);JFrame frame = new JFrame(
); and frame.setVisible(true);
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).
我想在用户点击第一个计算按钮时打开一个新的 JFrame 并用作输出窗口(如果您熟悉它们,则类似于 SPSS 输出窗口)。
don't do that, create only two JFrames , reuse 2nd. 不要那样做,只创建两个 JFrames ,重用第二个。
JFrame
by using getContentPane.removeAll()
, for another actions from JButton
JFrame
使用getContentPane.removeAll()
,用于来自JButton
其他操作
then all lifecycle will be only about setVisible(true)
/ setVisible(false)
那么所有生命周期都将仅与
setVisible(true)
/ setVisible(false)
change DefaultCloseOperations
to HIDE_ON_CLOSE
将
DefaultCloseOperations
更改为HIDE_ON_CLOSE
The New JFrame will be completely separate and will have its own menu bar.
New JFrame 将是完全独立的,并将拥有自己的菜单栏。 A simple JDialog is not the way to go here.
一个简单的 JDialog 不是这里的方法。
JDialog
, only one button in the Toolbar
in compare with three buttons in JFrame
, simple disagree, JDialog
什么问题,与JFrame
三个按钮相比, Toolbar
中只有一个按钮,简单不同意,Output window (Simlar to SPSS output windows if you are familiar with them).
输出窗口(如果您熟悉它们,则类似于 SPSS 输出窗口)。
SwingWorker
or Runnable#Thread
(required wrap into invokeLater
) for get value for JComponents placed into JDialog, if all changes are done call JDialog.setVisible(true)
wrapped into invokeLater()
SwingWorker
或Runnable#Thread
(需要包装到invokeLater
)获取放置到 JDialog 中的 JComponent 的值,如果所有更改都完成,调用JDialog.setVisible(true)
包装到invokeLater()
JFrame newFrame = new JFrame();
newFrame.setVisible(true);
Never use more than one JFrame
within a Swing application.切勿在一个 Swing 应用程序中使用多个
JFrame
。 Use JDialog
for extra windows instead.将
JDialog
用于额外的窗口。
See The Use of Multiple JFrames, Good/Bad Practice?请参阅使用多个 JFrame,好的/坏的做法? .
.
I maybe mis understanding your question but我可能误解了你的问题,但
JFrame frame = new JFrame();
frame.setVisible(true);
I used code JFrame frame = new JFrame(); frame.setVisible(true);
我使用了代码
JFrame frame = new JFrame(); frame.setVisible(true);
JFrame frame = new JFrame(); frame.setVisible(true);
. . This block of code just do empty window.
这段代码只是做空窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.