Hopefully simply display problem: nothing shows in jpanel

Hello all, I’m trying to get a simple jME demo going within a larger architecture. Specifically, I’m trying to get a physics test world (from the jME test code) to display in a JPanel. My current code is as follows:



[java] public JMESimViewer(ADEGuiCallHelper helper) {

super(helper, 100);

app = new Application();



AppSettings settings = new AppSettings(true);

settings.setCustomRenderer(AwtPanelsContext.class);

app.setSettings(settings);

app.setPauseOnLostFocus(false);

app.createCanvas();



setUpPanel();



BulletAppState bulletAppState = new BulletAppState();

app.getStateManager().attach(bulletAppState);

createPhysicsTestWorld(root, app.getAssetManager(), bulletAppState.getPhysicsSpace());

createBallShooter(app, root, bulletAppState.getPhysicsSpace());



}



void setUpPanel() {

final AwtPanelsContext ctx = (AwtPanelsContext)app.getContext();

AwtPanel panel = ctx.createPanel(PaintMode.Accelerated);

add(panel, BorderLayout.CENTER);

app.startCanvas(true);





// make the canvas fill the window, copied from NetBeans designer

GroupLayout layout = new GroupLayout(this);

setLayout(layout);

layout.setHorizontalGroup(layout.createParallelGroup(

GroupLayout.Alignment.LEADING).addComponent(

panel, GroupLayout.DEFAULT_SIZE,

GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));

layout.setVerticalGroup(layout.createParallelGroup(

GroupLayout.Alignment.LEADING).addComponent(

panel, GroupLayout.DEFAULT_SIZE,

GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));

}

[/java]



I’ve been reading through both TestAwtPanels and TestCanvas trying to get it to display, but I don’t see what I’m doing wrong.



The current output is a blank window (solid default-java-gray). It also spits a bunch of info log messages about adding things to the physics space, and finally it says EDT: addNotify followed by two EDT componentResized that correctly display the size of the JPanel.



Any suggestions? Hopefully I’m just failing to call something important, or some other similarly noobish mistake.

First noob mistake discovered: I was mixing canvases and panels. Switched to using JmeCanvasContext and .getCanvas in the relevant places. Now I can see blackness!



I also can’t help but note that one of the info messages near the bottom says “Deleting objects and invalidating state”. Is that a problem?



Also, between canvas and panels is there a significant difference? Assuming that no matter which I use I’m embedding it in a panel that I already have on screen, does it matter at all?

Normally a blank grey canvas like that means a fatal exception happened somewhere, are you sure there are no errors in the logs?

Yes, I am absolutely sure there were no exceptions.



Edit: although, it’s worth pointing out that after it has failed to display anything when I then click on the stop debug mode button I get an opengl segfault. I think this is caused by the stop button doing a forceful enough stop that things don’t get cleaned up nicely.

Second newb mistake, I hadn’t been calling attachScene(root). My code now looks like this:



[java] public JMESimViewer(ADEGuiCallHelper helper) {

super(helper, 100);

app = new Application();



AppSettings settings = new AppSettings(true);

// settings.setCustomRenderer(AwtPanelsContext.class);

app.setSettings(settings);

app.setPauseOnLostFocus(false);

app.createCanvas();



setUpPanel();



SwingUtilities.invokeLater(new Runnable() {

@Override

public void run() {

BulletAppState bulletAppState = new BulletAppState();

app.getStateManager().attach(bulletAppState);

createPhysicsTestWorld(root, app.getAssetManager(), bulletAppState.getPhysicsSpace());

// createBallShooter(app, root, bulletAppState.getPhysicsSpace());

app.getViewPort().attachScene(root);

}

});

}



void setUpPanel() {

final JmeCanvasContext ctx = (JmeCanvasContext)app.getContext();

// final AwtPanelsContext ctx = (AwtPanelsContext)app.getContext();

Canvas panel = ctx.getCanvas();

// AwtPanel panel = ctx.createPanel(PaintMode.Accelerated);

add(panel, BorderLayout.CENTER);

app.startCanvas(true);





// make the canvas fill the window, copied from NetBeans designer

GroupLayout layout = new GroupLayout(this);

setLayout(layout);

layout.setHorizontalGroup(layout.createParallelGroup(

GroupLayout.Alignment.LEADING).addComponent(

panel, GroupLayout.DEFAULT_SIZE,

GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));

layout.setVerticalGroup(layout.createParallelGroup(

GroupLayout.Alignment.LEADING).addComponent(

panel, GroupLayout.DEFAULT_SIZE,

GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));

}

[/java]



And it still just shows black, with no errors. Any ideas/helpful criticisms?

In the src/test is a render to swing render to memory example. That works by copying the output to a bufferdimage. Not as fast as directly using the canvas, but might work for you.

That may come in handy later, thanks! Can I also take that to mean that using a canvas is faster than using a panel?