Hello,
I’m working with JMonkey for years and i’ve tried tu update it to version 3.1beta2 with lwjgl3. It seems that within this configuration, i cannot create JMECanvas for an integration with Swing.
This code was functional with JMonkey 3.0 on LWJGL2:
package sample;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
public class SwingPanel extends JPanel {
private static final long serialVersionUID = 1L;
SimpleApplication application = null;
public SwingPanel(){
super();
setLayout(new BorderLayout());
AppSettings applicationSettings = new AppSettings(true);
applicationSettings.setWidth(1024);
applicationSettings.setHeight(768);
application = new SimpleApplication(){
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
};
application.setSettings(applicationSettings);
application.setPauseOnLostFocus(false);
application.createCanvas();
JmeCanvasContext ctx = (JmeCanvasContext) application.getContext();
add(ctx.getCanvas(), BorderLayout.CENTER);
}
public static void main(String[] args){
SwingPanel pn = new SwingPanel();
JFrame frame = new JFrame("SwingPanel");
frame.setSize(new Dimension(640, 480));
frame.setPreferredSize(new Dimension(640, 480));
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(pn, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
But now when o use it within JMonkey 3.1beta2 and jme3-lwjgl3 library i get the exception:
janv. 18, 2017 1:32:51 PM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.1-beta2
* Branch: HEAD
* Git Hash: a71fb28
* Build Date: 2016-11-22
janv. 18, 2017 1:32:51 PM com.jme3.system.JmeDesktopSystem newContextLwjgl
GRAVE: CRITICAL ERROR: Context class is missing!
Make sure jme3_lwjgl-ogl is on the classpath.
java.lang.ClassNotFoundException: com.jme3.system.lwjgl.LwjglCanvas
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.jme3.system.JmeDesktopSystem.newContextLwjgl(JmeDesktopSystem.java:196)
at com.jme3.system.JmeDesktopSystem.newContext(JmeDesktopSystem.java:279)
at com.jme3.system.JmeSystem.newContext(JmeSystem.java:162)
at com.jme3.app.LegacyApplication.createCanvas(LegacyApplication.java:511)
at sample.SwingPanel.<init>(SwingPanel.java:50)
at sample.SwingPanel.main(SwingPanel.java:58)
Exception in thread "main" java.lang.NullPointerException
at com.jme3.system.JmeDesktopSystem.newContext(JmeDesktopSystem.java:280)
at com.jme3.system.JmeSystem.newContext(JmeSystem.java:162)
at com.jme3.app.LegacyApplication.createCanvas(LegacyApplication.java:511)
at sample.SwingPanel.<init>(SwingPanel.java:50)
at sample.SwingPanel.main(SwingPanel.java:58)
The class com.jme3.system.lwjgl.LwjglCanvas is not found and i’ve seen that it is no more present within the jme3-lwjgl3 jar.
My question is so: Is it possible to integrate rendering canvas within a Swing application using JMonkey 3.1beta2 and jme3-lwjgl3 ?