JavaFX embedded in jme3

I kinda agree that it will be easier to support JFX without having to worry if user’s JRE has it installed or not (looking at you, openJDK).

Between jlink and the fact that JFX is going to be separated from the JDK, I have high hopes for the future of Java on the desktop.

I have problems using the library. TestJavaFXInJME always gives me an exception and I can’t find the fix. Anybody having the same problem?

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ClassCastException: com.jme3.system.lwjgl.LwjglDisplay cannot be cast to com.jme3.system.lwjgl.LwjglWindow
at com.jme3x.jfx.injme.util.JmeWindowUtils.getWidth(JmeWindowUtils.java:61)
at com.jme3x.jfx.injme.JmeFxContainerImpl.fitSceneToWindowSize(JmeFxContainerImpl.java:590)
at com.jme3x.jfx.injme.JmeFxContainerImpl.(JmeFxContainerImpl.java:336)
at com.jme3x.jfx.injme.JmeFxContainerImpl.install(JmeFxContainerImpl.java:87)
at com.jme3x.jfx.injme.JmeFxContainerImpl.install(JmeFxContainerImpl.java:72)
at com.jme3x.jfx.injme.JmeFxContainer.install(JmeFxContainer.java:26)
at com.jme3x.jfx.TestJavaFxInJme.simpleInitApp(TestJavaFxInJme.java:51)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:220)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
at java.lang.Thread.run(Thread.java:745)

FYI, line 61 reads:

final LwjglWindow lwjglContext = (LwjglWindow) context;

it seems you use lwjgl2, I support only lwjgl3 :slight_smile:

I use LWJGL3 too, but I think my LWJGL imports are fighting each other. How do you set it up properly?

I manually added LWJGL 3.1.6, GLFW, and the jme3-lwjgl3-3.3.0-SNAPSHOT jars libraries.

it happens else when you load the same class twice, for example, when you use two dirrent class loaders.

Hi javasabr,

I tried to use your test example descibed in git section: “How to integrate javaFX UI to jME application”.
As soon as this code is called:

container = JmeFxContainer.install(this, getGuiNode());

I get the same error:

com.jme3.system.lwjgl.LwjglDisplay cannot be cast to com.jme3.system.lwjgl.LwjglWindow

I develop using Visual Studio Code with maven,
JME3.2.0 stable
How should I switch lwgl?
So far it is requested as recommended in JME3 manual:

<dependency>
  <groupId>${jme3_g}</groupId>
  <artifactId>jme3-lwjgl</artifactId>
  <version>${jme3_v}</version>
  <scope>runtime</scope>
</dependency>

Could you please recommend? I am relatively newbie in maven topics…

I think you need to use the dependency ‘jme3-lwjgl3’ instead of ‘jme3-lwjgl’

1 Like

Hi Javasabr,

thank you it worked :slight_smile:

But I get very strange errors:

  1. when trying to test the basic scenario “Integrate into ImageView”.
    When I just have in my code this import:
    import com.jme3x.jfx.injfx.JmeToJFXIntegrator;

I get error:
Failed to resolve classpath: Main class ‘com.jme3…Main’ doesn’t exist in the workspace.
If I comment/delete this line with the import the app starts…

  1. When I test “JavaFX UI to JME Application”,
    once I call this line in “simpleInitApp”:
    JmeFxContainer container = JmeFxContainer.install(this, getGuiNode());
    I get error:

Mainclass cannot be initialized
Reason: java.lang.VerifyError: (class: com/jme3vscode/template/application/Main, method: simpleInitApp signature: ()V) Illegal type in constant pool

I am using Visual Studio code with maven, JME 3.2.0 stable, java 9.0.4.
Do you know why it could happen?

which verison of the library do you use? if 1.7.5-Final, it doesn’t support java 9+, only java 8.

here is an example how to use javaFX 11 which is not part of Oracle jRE 11

1 Like

Hello,

I’m working on a Maven JavaFX project with Eclipse.
I’ve been trying to use JME3-JFX, that I dowloaded here: GitHub - empirephoenix/JME3-JFX: JFX Gui bridge for JME with usefull utilities for common usecases , to add my JME3 application into a JavaFX ImageView, but I get this error:

Exception in thread “JavaFX Application Thread” java.lang.ClassCastException: com.jme3.system.lwjgl.LwjglDisplay cannot be cast to com.jme3.jfx.injfx.JmeOffscreenSurfaceContext
at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.bindDestination(AbstractFrameTransferSceneProcessor.java:381)
at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:38)
at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:15)
at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.lambda$bind$4(AbstractFrameTransferSceneProcessor.java:360)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:844)

These are my dependencies in pom.xml:

org.jmonkeyengine jme3-lwjgl3 3.2.0-stable jar
<dependency>
	<groupId>org.jmonkeyengine</groupId>
	<artifactId>jme3-core</artifactId>
	<version>3.2.1-stable</version>
</dependency>

What should I do ? Are the jme3 dependencies too recent maybe ? Thanks for help and for providing these tools !

Sorry, here is my second dependency needed for JME JFX:

org.jmonkeyengine jme3-lwjgl3 3.2.0-stable

(it’s not showing up properly)

And sorry, I forgot to add the java code:

		ImageView imageView = new ImageView();
	        
		AppSettings settings = JmeToJfxIntegrator.prepareSettings(new AppSettings(true), 60);
	   	settings.setRenderer(AppSettings.LWJGL_OPENGL2);
	   	settings.put("Width", 800);
	   	settings.put("Height", 600);
	   	settings.put("Title", "Vue 3D");
	   	settings.put("VSync", true);
	   	settings.put("Samples", 4);//Anti-Aliasing

	    VersperaApplication application = new VersperaApplication();
	    application.setSettings(settings);
	    application.setShowSettings(false);
	    	  
	    	 
		
					    
		Interface3DPanel interf=new Interface3DPanel(_view.baseImagePath) ;
		interf.vaImageView = imageView;
		interf.getChildren().add(interf.vaImageView);
		application.panel=interf;
			    	  
		JmeToJfxIntegrator.startAndBindMainViewPort(application, imageView, Thread::new);

			    	  try {
						Thread.sleep(1000, 0);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			    	  _model.camchase=new VersperaChaseCamera(application.getCamera(),application.getInputManager());
			    	  
			    	  _model.camchase.setMaxVerticalRotation((float)Math.PI*2.0f);
			    	  _model.camchase.setMinVerticalRotation(-(float)Math.PI*2.0f);
			    	  _model.camchase.setDownRotateOnCloseViewOnly(false);
			    	  
			    	  
			    	  application.enqueue(new Callable<Spatial>() {
					        public Spatial call() throws Exception {
					        	application.getAssetManager().registerLocator(_model.baseShaderResourcePath, FileLocator.class);
					        	application.getAssetManager().registerLocator(_model.baseImagePath, FileLocator.class);
					        	DirectionalLight l1=new DirectionalLight();
					        	l1.setDirection(new Vector3f(1.0f,0.0f,0.0f));
					        	DirectionalLight l2=new DirectionalLight();
					        	l2.setDirection(new Vector3f(-1.0f,0.0f,0.0f));
					        	DirectionalLight l3=new DirectionalLight();
					        	l3.setDirection(new Vector3f(0.0f,1.0f,0.0f));
					        	DirectionalLight l4=new DirectionalLight();
					        	l4.setDirection(new Vector3f(0.0f,-1.0f,0.0f));
					        	AmbientLight al = new AmbientLight();
					        	DirectionalLight pl=new DirectionalLight();
					        	pl.setColor(new ColorRGBA(1f,1f,1f,1.0f));
					        	pl.setDirection(application.getCamera().getDirection());
					        	application.getRootNode().addLight(pl);
					           
								Sphere sp=new Sphere(30,30,1.0f);
							    Geometry sphere=new Geometry("sphere",sp);
								Material mat=new Material(application.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); 
								mat.setColor("Color", ColorRGBA.Green);
								mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
								sphere.setMaterial(mat);
								_model.nodetarget=new Node();
								_model.nodetarget.setName("target");
								_model.nodetarget.attachChild(sphere);
								_model.nodetarget.addControl(_model.camchase);
								application.getRootNode().attachChild(_model.nodetarget);
							
					        	return null;
					        }
					    });
			    	  application.startCanvas();
			    	  
			    	  
			    	  
						Scene scene3D = new Scene(interf, 1440, 720);
				    	  
						Stage stage3D = new Stage();
						stage3D.setScene(scene3D);
						stage3D.setTitle("Verspera - Fenêtre 3D");
						stage3D.show();

The problem is both the javafx stage and the JME application are being displayed, but the JME application is not embedded within the javafx stage’s ImageView.

Thanks for helping

because you override the render setting, you don’t need to do it.

hello. what’s wrong with Nifty , Tonegode, Lemur? fx official not supported in engine? i am newbie :frowning_face:
GitHub - JavaSaBr/JME3-JFX: JFX Gui bridge for JME with usefull utilities for common usecases WOW!!! cool

everything is ok with these libraries, but I prefer to use javaFX as most powerful GUI framework.

Thanks for the reply. I tried removing that line but now the JME window is not showing up anymore. No more exceptions in the console, but I get this:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.1-stable/jme3-core-3.2.1-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
juil. 06, 2018 11:10:48 AM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.2-stable

  • Branch: HEAD
  • Git Hash: f85624a
  • Build Date: 2018-01-21
    juil. 06, 2018 11:10:49 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
    INFOS: LWJGL 3.1.2 build 29 context running on thread Thread-2
  • Graphics Adapter: GLFW 3.3.0 X11 GLX EGL clock_gettime /dev/js shared
    juil. 06, 2018 11:10:49 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
    INFOS: OpenGL Renderer Information
  • Vendor: Intel Open Source Technology Center
  • Renderer: Mesa DRI Intel® Haswell Desktop
  • OpenGL Version: 3.3 (Core Profile) Mesa 11.2.2
  • GLSL Version: 3.30
  • Profile: Core
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
    juil. 06, 2018 11:10:49 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.audio.plugins.OGGLoader
    juil. 06, 2018 11:10:49 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio Renderer Information
  • Device: OpenAL Soft
  • Vendor: OpenAL Community
  • Renderer: OpenAL Soft
  • Version: 1.1 ALSOFT 1.17.2
  • Supported channels: 64
  • ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFTX_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFTX_output_limiter ALC_SOFT_pause_device
  • AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_block_alignment AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_gain_clamp_ex AL_SOFT_loop_points AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize
    juil. 06, 2018 11:10:49 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio effect extension version: 1.0
    juil. 06, 2018 11:10:49 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio max auxiliary sends: 2
    juil. 06, 2018 11:10:49 AM com.jme3.system.lwjgl.LwjglWindow create
    AVERTISSEMENT: create() called when display is already created!
    juil. 06, 2018 11:10:50 AM com.jme3.util.ReflectionAllocator destroyDirectBuffer
    GRAVE: Buffer cannot be destroyed: java.nio.DirectByteBuffer[pos=4 lim=4 cap=4]

I got the warnings in the beginning even before removing the “setRenderer” line though:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.jme3.util.ReflectionAllocator (file:/users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.1-stable/jme3-core-3.2.1-stable.jar) to method sun.nio.ch.DirectBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.jme3.util.ReflectionAllocator
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
juil. 06, 2018 11:13:46 AM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.2-stable

  • Branch: HEAD
  • Git Hash: f85624a
  • Build Date: 2018-01-21
    juil. 06, 2018 11:13:46 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
    INFOS: LWJGL 3.1.2 build 29 context running on thread Thread-2
  • Graphics Adapter: GLFW 3.3.0 X11 GLX EGL clock_gettime /dev/js shared
    juil. 06, 2018 11:13:46 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
    INFOS: OpenGL Renderer Information
  • Vendor: Intel Open Source Technology Center
  • Renderer: Mesa DRI Intel® Haswell Desktop
  • OpenGL Version: 3.0 Mesa 11.2.2
  • GLSL Version: 1.30
  • Profile: Compatibility
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
    juil. 06, 2018 11:13:46 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.audio.plugins.OGGLoader
    juil. 06, 2018 11:13:46 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio Renderer Information
  • Device: OpenAL Soft
  • Vendor: OpenAL Community
  • Renderer: OpenAL Soft
  • Version: 1.1 ALSOFT 1.17.2
  • Supported channels: 64
  • ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFTX_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFTX_output_limiter ALC_SOFT_pause_device
  • AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_block_alignment AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_gain_clamp_ex AL_SOFT_loop_points AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize
    juil. 06, 2018 11:13:46 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio effect extension version: 1.0
    juil. 06, 2018 11:13:46 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio max auxiliary sends: 2
    juil. 06, 2018 11:13:47 AM com.jme3.system.lwjgl.LwjglWindow create
    AVERTISSEMENT: create() called when display is already created!
    Exception in thread “JavaFX Application Thread” java.lang.ClassCastException: com.jme3.system.lwjgl.LwjglDisplay cannot be cast to com.jme3.jfx.injfx.JmeOffscreenSurfaceContext
    at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.bindDestination(AbstractFrameTransferSceneProcessor.java:381)
    at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:38)
    at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:15)
    at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.lambda$bind$4(AbstractFrameTransferSceneProcessor.java:360)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    at java.base/java.lang.Thread.run(Thread.java:844)

Do you have any ideas ? Thanks.

it looks like you override the setting “settings.setCustomRenderer(…);” somewehere, but I don’t see it in your code,
Do the examples from README work on your machine?

I looked for it but I didn’t override it. I get 404 errors when trying to open the links with the examples on the README