JMonkey TabbedPane Issue

Hi,



So I am trying to integrate a Jmonkey Object inside of a TabbedPane.



If I switch to the tab that contains the 3D effect really quickly it will work. However if I wait for a bit then switch to the tab the 3d jmonkey effect is missing. How do I ensure that the Jmonkey code will appear if I switch to the tab later.



A simple example code is below.



Thanks,

Simran Basi



/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package jme3test.helloworld;



    import com.jme3.app.SimpleApplication;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.Node;

    import com.jme3.scene.shape.Box;

    import com.jme3.system.AppSettings;

    import com.jme3.system.JmeCanvasContext;

    import com.jme3.texture.Texture;

    import java.awt.Dimension;

    import java.awt.FlowLayout;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JPanel;

    import javax.swing.JTabbedPane;

    import javax.swing.JTextArea;



    /**
  • you can embed a jme canvas inside a swing application
  • @author pgi

    /

    public class SwingCanvasTest extends SimpleApplication {





    protected Geometry platform, p_line;

    Node pivot;

    @Override

    public void simpleInitApp() {



    Box b = new Box(Vector3f.ZERO, (float)2, (float).05, (float)1);

    platform = new Geometry(“red cube”, b);

    Material mat = new Material(assetManager,

    “Common/MatDefs/Misc/Unshaded.j3md”);

    mat.setColor(“Color”, ColorRGBA.Red);

    platform.setMaterial(mat);

    //rootNode.attachChild(platform);



    Box b2 = new Box(Vector3f.ZERO, (float)2.01, (float).1, (float).1);

    p_line = new Geometry(“yellow cube”, b2);

    Material mat2 = new Material(assetManager,

    “Common/MatDefs/Misc/Unshaded.j3md”);

    mat2.setColor(“Color”, ColorRGBA.Yellow);

    p_line.setMaterial(mat2);

    //rootNode.attachChild(p_line);





    pivot = new Node(“pivot”);

    rootNode.attachChild(pivot); // put this node in the scene



    /
    * Attach the two boxes to the pivot node. /

    pivot.attachChild(platform);

    pivot.attachChild(p_line);





    }



    /
    This is the update loop /

    @Override

    public void simpleUpdate(float tpf) {

    // make the player rotate

    pivot.rotate(0, 2
    tpf, 0);



    //platform.rotate(0, 2tpf, 0);

    //p_line.rotate(0, 2
    tpf, 0);

    }

    /public void simpleInitApp() {

    // activate windowed input behaviour

    flyCam.setDragToRotate(true);

    // display a cube

    Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);

    Geometry cube = new Geometry(“My Textured Box”, boxshape1);

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

    Texture tex_ml = assetManager.loadTexture(“Interface/Logo/Monkey.jpg”);

    mat_stl.setTexture(“m_ColorMap”, tex_ml);

    cube.setMaterial(mat_stl);

    rootNode.attachChild(cube);

    }
    /



    public static void main(String[] args) {

    java.awt.EventQueue.invokeLater(new Runnable() {



    public void run() {

    // create new JME appsettings

    AppSettings settings = new AppSettings(true);

    settings.setWidth(640);

    settings.setHeight(480);



    // create new canvas application

    SwingCanvasTest canvasApplication = new SwingCanvasTest();

    canvasApplication.setSettings(settings);

    canvasApplication.createCanvas(); // create canvas!

    JmeCanvasContext ctx = (JmeCanvasContext) canvasApplication.getContext();

    ctx.setSystemListener(canvasApplication);

    Dimension dim = new Dimension(640, 480);

    ctx.getCanvas().setPreferredSize(dim);



    // Create Swing window

    JFrame window = new JFrame(“Swing Application”);

    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



    // Fill Swing window with canvas and swing components

    JPanel panel = new JPanel(new FlowLayout()); // a panel

    panel.add(ctx.getCanvas()); // add JME canvas

    panel.add(new JButton(“Swing Component”)); // add some Swing



    JTabbedPane tabbedPane = new JTabbedPane();

    tabbedPane.addTab(“Blank”, new JPanel());

    tabbedPane.addTab(“Jmonkey effect”, panel);

    window.add(tabbedPane);

    window.pack();



    // Display Swing window including JME canvas!

    window.setVisible(true);

    canvasApplication.setPauseOnLostFocus(false);

    canvasApplication.startCanvas();

    }

    });

    }

    }

Turned out to be OS specific. Works in windows not mac

Use AWT panels instead (see TestAwtPanels example).



The canvas has various OS specific issues.