[英]Java - Swing GUI Window Order
In the following code, why is the "My Application" window the window at the front? 在以下代码中,为什么“我的应用程序”窗口位于最前面? The main method constructs this window first, right?
main方法首先构造此窗口,对吗? So shouldn't it be at the back when the "My Window" JFrame is produced?
那么在生成“我的窗口” JFrame时不应该在后面吗?
public class MyApp extends JFrame {
public MyApp() {
super();
setSize(300,600);
setTitle("My Application");
setVisible(true);
}
public static void main(String[] args) {
MyApp application = new MyApp();
JFrame window = new JFrame();
window.setSize(600,300);
window.setTitle("My Window");
window.setVisible(true);
}
}
This is simply undefined behavior; 这只是未定义的行为。 there's no guarantee that either window will always be in front.
不能保证任何一个窗口始终位于前面。 When I ran your code (Mac OS X, Java 6), "My Window" came up in front, but I have no doubt you're correctly describing what happens on your system.
当我运行您的代码(Mac OS X,Java 6)时,“我的窗口”出现在前面,但是毫无疑问,您正确地描述了系统中发生的情况。
1) you can't move one JFrame toFront()
over another JFrame
1)你不能移动一个JFrame的
toFront()
在另一个JFrame
2) don't create more than one JFrame
, there are another issues with this Top-Level Container
as toFront
, toBack
2)不要创建多个
JFrame
,此Top-Level Container
还有另一个问题,如toFront
, toBack
3) you have look at JDialog
or JWindow
as another Window 3)您将
JDialog
或JWindow
视为另一个窗口
with parent
to the JFrame
与
JFrame
parent
一起
with setModal
if required 使用
setModal
如果需要)
with ModalityTypes
is required 需要
ModalityTypes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.