简体   繁体   English

Java-同一窗口上的另一个JFrame

[英]Java - Another JFrame On Same Window

What I want is to make a new JFrame, keeping my current JFrame visible, but not create a new window/program. 我想要的是制作一个新的JFrame,同时保持当前的JFrame可见,但不创建一个新的窗口/程序。 I can't explain it well, so here is a picture of what I mean: 我不能很好地解释它,所以这是我的意思的图片:

http://screensnapr.com/e/mkCMlm.png http://screensnapr.com/e/mkCMlm.png

Sorry if this is confusing in any way. 抱歉,如果以任何方式造成混淆。 Any help is appreciated. 任何帮助表示赞赏。

You can try http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html 您可以尝试http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html

Also you can try to use a dialog rather than frame for the new window. 您也可以尝试使用对话框而不是新窗口的框架。

If I understood correctly you want JInternalFrame which are a special component in swing that live inside a Container named Desktop. 如果我理解正确,则需要JInternalFrame,它是swing中的一个特殊组件,它位于名为Desktop的容器中。 So if you want to have a behaviour like this: 因此,如果您想要这样的行为:

在此处输入图片说明

You definitely need to have inside your JFrame a container named JDesktopPane , then you can add JInternalFrame inside this container like this: 您绝对需要在JFrame中有一个名为JDesktopPane的容器,然后可以在此容器中添加JInternalFrame,如下所示:

 MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame);
    try {
        frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {ex.printStackTrace();}

For more information you can see official oracle documentation or Java2SE code samples 有关更多信息,请参见正式的oracle文档Java2SE代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM