General - Putting a JME Display in a Swing GUI


i have a question about JME.

I want to integrate a simple JME "universe" into a swing GUI. Here is the JME Program and everything works fine. I just want to show it in a swing gui, and i dont know how. I read something about the method createCanvas() but when i try to integrate that canvas in a swing gui, i cant see anything.

It'll be nice to see an example code of how i can show my JME Programm in swing GUI.

Excuse my bad engilish :smiley:

public static void main( String[] args ){
      new FinalIsland();

   protected void simpleInitGame()
      display.setTitle( "Final Island" );

      // set up the scene graph
      Node terrainScene = new Node( "terrainScene" );
      // create the skybox
      skybox = new SkyBox( terrainScene, cam.getLocation() );
      // create the terrain
      terrain = new Terrain( terrainScene );
      // create the water
      water = new Water( terrainScene, 39.7147f );

      // create a jeep
      jeep = new Jeep( terrainScene );
      jeep.setPosition( new Vector3f( 167, terrain.getHeightAt( 167, 190 ), 190 ) );

      // simulate a sun
      LightState ls = display.getRenderer().createLightState();
      DirectionalLight light = new DirectionalLight();
      light.setDirection( new Vector3f( 0.6f, -0.75f, 0.6f ) );
      float intensity = 1.0f;
      light.setDiffuse( new ColorRGBA( intensity, intensity, intensity, 1.0f ) );
      light.setAmbient( new ColorRGBA( intensity, intensity, intensity, 1.0f ) );
      light.setEnabled( true );
      ls.attach( light );
      terrainScene.setRenderState( ls );

      // switch of the standard light

      // attach the whole scene and update the render states
      rootNode.attachChild( terrainScene );

      // move the camera to the middle of the island
      cam.setLocation( new Vector3f( 150, 80, 180 ) );

I can just issue a warning to think about when using jme inside a swing gui (at least I never solved this problem).

Think about that you have to use awt as input instead of LWJGL, and the effect of this is that the awt mouse have a different coordinatesystem than jME usually uses. In jME, origo is in the lower left corner of the screen, but in awt origo is in the upper left corner. This will cause problem for you if you want to use cameras which are made for jME, since they won't behave as intended.

If you are aware of this from the beginning it might be easier to adapt your program to this.

If anyone has a solution to using jME inside of swing without having to use awt (or solve it in another way), please let me know.

There's a "flip" variable which you can enable which allows for this to be handled, as well as an entirely different class called AWTMouseInput which helps you deal with it as well.

While getting the GLCanvas and Implementor classes to actually run in the Window is very convoluted and needs to be clarified, the actual game code needs few (if any) changes to run.

thx a lot 4 the fast answers. Helps me a lot