0

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? 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? Is it possible to get a Graphics object from a PID, or some other reference to the program?

EDIT: I'm doing this in Linux, on XOrg, preferably on Debian Squeeze

Terra
  • 25
  • 9
  • 6
    just... don't even try – 0x6C38 Jun 10 '13 at 22:11
  • 4
    It sounds like you want to create a JInternalFrame inside of a JDesktopPane. If that's not what you want to do, then I agree with @MrD. – Hovercraft Full Of Eels Jun 10 '13 at 22:11
  • 1
    See also [Working with 2 or more frames](http://stackoverflow.com/q/7889922/418556). – Andrew Thompson Jun 10 '13 at 23:50
  • 1
    Do you have access to the code for all the JFrames? – Code-Apprentice Jun 11 '13 at 00:50
  • First off thank you for responding, but i guess i did word my question a little off. I want to basically listen in on x11 and see when a program is launched. When a program is launched, instead of its own window, i would like to launch it into a seperate, existing window aka, my program. – Terra Jun 11 '13 at 19:51
  • @Terra: that is a very bad idea and one that Swing and Java are almost uniquely ill-suited for. I suggest you consider not doing this, or if it is necessary, do it with a language that gets closer to the OS and to the metal such as C++. – Hovercraft Full Of Eels Jun 12 '13 at 02:08
  • @HovercraftFullOfEels, would it then be possible for me to use JNI with a C++ program, just because i don't feel like recoding my entire program in a language i know little about. – Terra Jun 16 '13 at 12:51

2 Answers2

1

It is possible to launch a JFrame inside a JFrame but I would consider it a very bad practice. Look at this for example:

JFrame frame1 = new JFrame();
JFrame frame2 = new JFrame();
frame1.add(frame2);
frame1.setVisible(true);

This code would still run but it is better to put a JPanel inside a JFrame instead.

0

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!

Mohammadreza Khatami
  • 1,444
  • 2
  • 13
  • 27