I have been trying to get a simple scene rendered in a JPanel. The guides I have see focus on directly building the Frame and components within the project’s run() method, but I want a more generic panel that I can reuse across multiple applications. What I want is a little backwards from what the examples show - my main GUI is external and trying to import the jme scene rather than building the GUI with the scene included. Basically, I want to be able to have 3 tiers:
Overall GUI → myJmeJPanel (extends JPanel) → myScene(extends SimpleApplication)
All of the 3d work should be hidden and totally isolated from the overall GUI and it should not see anything more than the creation of a custom JPanel, or equivalent functionality.
I have to work with multiple, fairly simple scenes that each extend SimpleApplication. I also have multiple different places in the GUI that will need the 3d components at different times. The scenes are simple, and I don’t have much going on in the scene (rotations, translations, etc), so performance is not my biggest concern.
Basically, I can’t figure out how to get a call that basically does:
ExternalGUI.add(new myJmeJPanel());
The standard sample forces me to attach the JPanel within the Runnable and does not provide a way that I can find to attach to the Class I wrote which extends JPanel. I also looked at the Scene Editor course
Several of the imports in that example are not supported (or I could not find them) in jme3... Display and Impl classes in particular. This is the closest I have seen to what I need, but I can't figure out how to replace those classes.
My basic desire is to simply be able to replace the standard JFrame code with a ".add(ctx.getCanvas())", which clearly does not work within the Runnable.
In the code below, GLSurfacePanel is the panel I want in between the main GUI and the Scene. GLSurface is the scene (extends SimpleApplication). I have a separate GUI that basically just does:
JPanel localPane =new GLSurfacePanel();
localGUI.add(localPane);
public class GLSurfacePanel extends javax.swing.JPanel {
public GLSurfacePanel() {
super();
initComponents(); //just sets the Layout right now
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
AppSettings settings = new AppSettings(true);
settings.setWidth(800);
settings.setHeight(600);
GLSurface canvasApplication = new GLSurface();
canvasApplication.setSettings(settings);
canvasApplication.createCanvas();
JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();
ctx.setSystemListener(canvasApplication);
Dimension dim = new Dimension(640, 480);
ctx.getCanvas().setPreferredSize(dim);
JFrame window = new JFrame("Test Application");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//GLSurfacePanel.this.add(ctx.getCanvas());
window.add(ctx.getCanvas());
window.pack();
window.setVisible(true);
canvasApplication.startCanvas();
//GLSurfacePanel.this.setVisible(true);
}
});
}
If I leave the JFrame in, then, obviously, an extra frame opens that runs my scene. If I comment out all of the frame items, then I can't figure out how to get the ctx.getCanvas() call into the JPanel rather than the Runnable. I suspect I am trying an approach that is totally inappropriate, but don't know enough about managing this to sort it out.
Can anyone point me in the right direction to create a custom JPanel that can fit these needs?