[SOLVED] JMonkey Freeze with Swing


I just started using JM3 a few weeks ago. Although i worked through a lot of tutorials, it seems that I just can’t get it right.

I have a huge GUI and the main function of my programm is not supposed to be a game. BUT there are some things

I would like to have visualized in 3D. (and it should be always updated) So I implemented a SimpleApplication in my SwingGUI.

(even with the tutorials i just couln’t manage to do it as a thread ):

so here is my version right now how i “start” jmonkey in my swing: This is all IN my “JFRAME” class.

[java]AppSettings settings = new AppSettings(true);



settings.setResolution(590, 590);





context = (JmeCanvasContext) app3D.getContext();

canvas = context.getCanvas();

canvas.setPreferredSize(new Dimension(560, 560));




so at first there is no problem and everything ist just fine.

But if the user presses a Button on the SwingGUI and starts a programm, which gets “new Points”, my app3D (the JMonkey Window) starts to freeze and i can’t move the camera anymore. (There is no problem with the swing components though)

So that you can understand the problem correctly, i have to tell you, that I tried to get those “new Points” as an Oberserver IN MY JMONKEY WINDOW… I don’t even know, if I can do this - or how. But I would guess that there lies my problem.


public void onNewCubeColor(CubeColorMsg cubeColorMsg) {

cubeIncomeColor = cubeColorMsg.getColor();

cubeIncomeX = cubeColorMsg.getxIntOfCube();

cubeIncomeY = cubeColorMsg.getyIntOfCube();

cubeIncomeZ = cubeColorMsg.getzIntOfCube();

Material red = new Material(assetManager, “Common/MatDefs/Misc/ColoredTextured.j3md”);

red.setColor(“Color”, new ColorRGBA(1,0,0,0.5f));


Box box = new Box(new Vector3f(cubeIncomeXcubeDimensionX,cubeIncomeYcubeDimensionY,cubeIncomeZ*cubeDimensionZ), cubeDimensionX, cubeDimensionY, cubeDimensionZ);

Geometry cube = new Geometry(“Box”, box);




as i said…the incoming points will be generated as soon as the user presses a special button.

BUT if the user presses something on the gui which doesn’t “interfere” with jmonkey there is no problem at all.

I don’t know if this information is important as well, but my Camera is set in public void simpleInitApp() {}

as well as the pivot will be generated and attached.

Do you think the problem is a thread one? Or do I have to handle the incoming points differently? Not as an observer-pattern I mean?

Can you advice me how to handle my problem??

Thank you so much !


The button presses are issued on the AWT thread, but you have to execute the calls on the OpenGL thread:

[snippet id=“10”]

Thanks for your fast answer :slight_smile:

I finally got it right :slight_smile:

so in case somebody has a similar problem (or especially understanding problem i guess)

here is my way to explain it:

My main problem was to “update” my jMonkey Canvas. I wanted to put new information into my already build

node / application.

So i simple attached my new cubes (in my case) to my node.

But the thread is getting confused then- so what you do is you put your commands in a queue - so the application can

visualize them when it is the right time for it :smiley:

so instead of simple attaching them, this is what i did:

[java] enqueue(new Callable() {

public Object call(){


return null;



i hope i don’t do something wrong in the background or whatever. But for me it works pretty well right now

thanks again, normen!