JME Canvas not rendered in right location

Hello all!

I’ve been hard a work on a 3D visualization project, and the JMonkey Engine has been working almost flawlessly so far! However, I do have one small problem.

The canvas does not render in the correct location. I have followed the instructions here and am able to create the canvas, and populate it. However, although it renders the scene correctly, the image itself is drawn at the wrong location in my JFrame. There are several other panels around the actual JME canvas, which are actually covered up at run time.

JME canvas rendered in wrong location

As shown in the picture, no matter where I place the Canvas component, it always renders in the top left corner of the JFrame. In this picture, the JME canvas should be in the panel on the right with the cyan outline.

I’ve noticed recently that it handles mouse events as if the Canvas were placed in the correct position.

Any ideas what i’m doing wrong? Here is the code snippet which adds the canvas to the Swing application

[java]
public class IanJavaTest
extends SimpleApplication
{
public static void main(String[] args){
IanJavaTest app = new IanJavaTest();
app.start();
}

@Override
public void simpleInitApp() {

    /** create a blue box at coordinates (1,-1,1) */
    Box box1 = new Box(1,1,1);
    Geometry blue = new Geometry("Box", box1);
    blue.setLocalTranslation(new Vector3f(1,-1,1));
    Material mat1 = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.Blue);
    blue.setMaterial(mat1);

    /** create a red box straight above the blue one at (1,3,1) */
    Box box2 = new Box(1,1,1);
    Geometry red = new Geometry("Box", box2);
    red.setLocalTranslation(new Vector3f(1,3,1));
    Material mat2 = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.Red);
    red.setMaterial(mat2);

    /** Create a pivot node at (0,0,0) and attach it to the root node */
    Node pivot = new Node("pivot");
    rootNode.attachChild(pivot); // put this node in the scene

    /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */
    pivot.attachChild(blue);
    pivot.attachChild(red);
    /** Rotate the pivot node: Note that both boxes have rotated! */
    pivot.rotate(.4f,.4f,0f);
}


public static void main(String[] args){
    this.kApp = new IanJavaTest();

    kApp.setPauseOnLostFocus(false);
    kApp.createCanvas();
    kApp.startCanvas(true);

    context = (JmeCanvasContext) kApp.getContext();
    this.canvas = context.getCanvas();

    kApp.startCanvas();
 	kApp.getFlyByCamera().setDragToRotate(true);


    JPanel testPanel = new TestPanel();
	testPanel.setLayout(new BorderLayout(0, 0));
	testPanel.add(canvas, BorderLayout.CENTER);
	testPanel.setBorder(new LineBorder(Color.CYAN, 2));

    this.getContentPane().setLayout(new MigLayout("fill, ins 0", "[50%!,grow,fill]0[50%!,grow,fill]", "[50%!,grow,fill]0[50%!,grow,fill]"));
	this.getContentPane().add(testPanel, "cell 1 0");
	JLabel label = new JLabel("Testing");
	label.setHorizontalAlignment(SwingConstants.CENTER);
	label.setBackground(Color.RED);
	label.setOpaque(true);
	label.setForeground(Color.WHITE);
	label.setAlignmentX(CENTER_ALIGNMENT);
	label.setAlignmentY(CENTER_ALIGNMENT);
	this.getContentPane().add(label, "cell 0 1,alignx center,aligny center");
}

}