views:

316

answers:

3

I created a Java application in NetBeans which consists of a bunch of components on a JPanel. I know want to embed this application on a frame which will be a completely separate application. I can't seem to be able to do this...any suggestions?

+2  A: 

This should be something like:

JFrame frame = new JFrame("Title");
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);

where panel is the panel that you want to show on the window.

Bruno Rothgiesser
Yeah, that's better than adding it to the content pane.
Michael Myers
+1 because I changed my answer after you posted this.
Michael Myers
+1  A: 

Do you mean you want to do this at runtime (application A makes the panel appear in application B) or are you simply having classpath issues (you're not sure how to add the panel to the classpath)?

In either case your panel needs to be on the classpath of the 'completely separate application'. There's several ways to do this, the simplest being simply to add the panel (or the JAR containing it) to the -classpath JVM argument. Then use code like BrunoRoth or mmyers have posted in the 'completely separate application' to display it.

If another application needs to control the when the panel is displayed in the 'completely separate application' then the 'completely separate application' will need to expose a remote procedure (probably using RMI) that causes this to happen.

Nick Holt
A: 

If you are using Matisse, you can do this one of two ways.

  1. Expand your jpanel jar file, navigate to the class, and drag-and-drop it onto your JFrame in the Matisse editor.
  2. On the palette, click on "Add Bean" and type in the fully-qualified name of the JPanel. Then click on the JFrame to place it.

You need to have the jpanel's jar file added to the project.

James Schek