Adding JME canvas to netbeans generated JFrame

I followed the JME swing tutorial for adding a canvas to a JFrame and I was successful in adding a canvas to a custom class I made that extends frame.

AppSettings settings = new AppSettings(true);

Main canvasApplication = new Main();
canvasApplication.createCanvas(); // create canvas!
JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();
Dimension dim = new Dimension(640, 480);

testframe window = new testframe();
JPanel panel = new JPanel(new FlowLayout()); // a panel
// add all your Swing components ...
panel.add(new JButton("Some Swing Component"));
// add the JME canvas



This works fine and my test GUI show with the canvas. However if change

testframe window = new testframe();


worldEditor window = new worldEditor ();

Where worldEditor is the JFrame I built using netbeans.

This causes my form to display but with no canvas. This only happens with the netbeans generated code. To be frank my editor is too complicated for me to build by hand and I really need to use the netbeans editor.

If someone could tell me what I’m doing wrong or point me in the right direction I would appreciate.

Make a panel in the gui editor and add the canvas to that (instead of trying to add your panel to the window).

I think handling the threading between Swing and jME is much more complicated and gets even more complicated when you do a Swing GUI with an editor but each to his own.

I already tried creating a place holder panel then adding the canvas.


Still nothing. This only happens when the code is generated from netbeans.

What are the alternatives to netbeans for creating frames with jmonkey ?

But did you set the layout for that panel? Best use box.

You’ll always have the threading issue when using Swing and jME together, no way around that.

Yes , I set the layout too. It seems to be something happening when the JFrame calls initComponents that is causing it to not work. I even created a second public panel and added it to the frame with the same result.

Okay I figured out the problem. You have to call pack in the constructor or else it doesn’t show.

gamePanel = new JPanel();
gamePanel.setPreferredSize(new Dimension(640,480));

I thought calling pack in the simpleApp class would work but apparently not. After setting it up in the constructor I just added it to the netbeans generated panel I was using as a place holder.

Dude, you seriously have to read up on Swing and the EDT thread. You can do NOTHING in Swing from another thread, except calling redraw, which only sets a flag that is worked off in the next frame of the Swing thread.

But what are the alternatives ? I already asked that. I need buttons , text/number boxes and etc in my app.

Getting your threading in order (again, theres documentation on this) or using one of the GUI systems for jME - nifty, lemur or even the discontinued tonegodgui.

I’m aware of th threading issuses , however I’ve had the same issues with nifty plus more. I haven’t tried Lemur’s yet but it is on my list. I have a working Jframe but it uses a master singular thread along with a static instance of the form , canvas and some custom listeners. Believe it or not this is the simplest way I have found so far.

I really would love to be to do everything I want in the jme IDE but unfortunately the AI I have implemented requires a custom editor but so far the majority of my work is done in the IDE.

If the netbeans editor doesn’t work I plan on taking some time out to learn about creating custom add ons to netbeans so I can just expand my work to be entirley done in the jme IDE.

My end goal is to create a gaming pipeline that is done entirely in JME without the help of outside libraries.