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?
views:
316answers:
3This 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.
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.
If you are using Matisse, you can do this one of two ways.
- Expand your jpanel jar file, navigate to the class, and drag-and-drop it onto your JFrame in the Matisse editor.
- 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.