简体   繁体   English

将一个JFrame启动到另一个JFrame

[英]Launching a JFrame into another JFrame

Is it possible for someone to launch a JFrame from a java program, but instead of the JFrame creating its own window, the java program launches it into an existing window? 有人可以从Java程序启动JFrame,但不是JFrame创建自己的窗口,而是Java程序将其启动到现有窗口中? I thought of trying a classloader, something like this: 我想到尝试一个类加载器,像这样:

    Class framed = WhateverClassThisIs.class.getClassLoader().loadClass("foo.class");
    JFrame launch = (JFrame) framed.newInstance();
    WhatEverJFrameBeingUsed.add(launch);

and then just simply add it to the container i'm using currently. 然后只需将其添加到我当前正在使用的容器中即可。 But what if the class references another JFrame, like a main class, how do i get that JFrame and contain it in the same existing JFrame? 但是,如果该类引用了另一个JFrame(如主类),该如何获取该JFrame并将其包含在相同的现有JFrame中呢? Is it possible to get a Graphics object from a PID, or some other reference to the program? 是否可以从PID或对该程序的其他引用中获取Graphics对象?

EDIT: I'm doing this in Linux, on XOrg, preferably on Debian Squeeze 编辑:我正在XOrg的Linux上,最好是在Debian Squeeze上这样做

yes it's possible but see this: 是的,这是可能的,但请参见以下内容:

 JFrame frame1 = new JFrame("First Window");
 JPanel panel = new JPanel("Second Window");
 frame1.add(panel,BordeLayout.CENTER);
 frame1.setSize(300,300);
 frame1.setVisible(true);

JPanel is a component that's be contained in a JFrame ,it's not illegal to have a main Window into another main Window! JPanel是一个包含在JFrame中的组件,将一个主窗口插入另一个主窗口是不合法的!

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

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