Rendering into a panel i can´t see my meshes until i click into the panel

I am making a tool to visualize meshes contained into a file type. I made a class for my UserInterface, this class is based on a frame that has a panel and some other components.
Then into my project I extend SimpleApp and configure it to render into the panel. When i add a box into simpleInitApp as a test it renders it ok, but when i select a subfile of my Jtree and create the meshes contained in it I have some problems.

As i didn´t saw none of the meshes created in method fillRootNodeWithMeshes I put a box into it to test if it works. The result is that statsview seems frozen and the box doesn´t appear until i click over the panel, then the box appears and the statsview disappears.

The problem of not seeing the meshes I suppose is because the cam doesn´t focus them so i need to find a way to make the cam look to the meshes and I need to know what I made wrong to cause that the box only appears after a click while the statsview disappears.

Here is my code:

[java]import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.eclipse.swt.widgets.Tree;
import org.omg.CORBA.INITIALIZE;

import com.jme3.app.SettingsDialog.SelectionListener;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;

public class MyFileEditor extends SimpleApplication implements TreeSelectionListener {
JFileChooser fileChooser;
UserInterfaceWindow uiWindow;

/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	EventQueue.invokeLater(new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			
			MyFileEditor myFileEditor= new MyFileEditor();
			myFileEditor.uiWindow= new UserInterfaceWindow();
			myFileEditor.uiWindow.tree.addTreeSelectionListener(myFileEditor);

			AppSettings settings= new AppSettings(true);
			settings.setHeight(myFileEditor.uiWindow.panel.getHeight());
			settings.setWidth(myFileEditor.uiWindow.panel.getWidth());
			myFileEditor.setSettings(settings);
			myFileEditor.createCanvas();

			JmeCanvasContext ctx = (JmeCanvasContext) myFileEditor.getContext();
			ctx.setSystemListener(myFileEditor);
			Dimension dim = new Dimension(myFileEditor.uiWindow.panel.getWidth(),myFileEditor.uiWindow.panel.getHeight());
			ctx.getCanvas().setPreferredSize(dim);
			myFileEditor.uiWindow.panel.add(ctx.getCanvas());


			myFileEditor.startCanvas();

		}
	});
	
}


public void setUpFileChooser(){
	fileChooser= new JFileChooser();
	fileChooser.setDialogTitle("Select File");
	FileNameExtensionFilter iffcdfFilter= new FileNameExtensionFilter("IFF/CDF Files","iff","CDF Files","cdf");
	fileChooser.addChoosableFileFilter(iffcdfFilter);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setFileFilter(iffcdfFilter);
	
}



@Override
public void simpleInitApp() {
	// TODO Auto-generated method stub
	
	flyCam.setDragToRotate(true);
	/*Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
    geom.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom);  */   
    
    System.out.println("simpleInitApp: "+rootNode.getChildren().toString());
}


//Gets the meshes list from a 3dmodel subfile and attach them to the rootnode
public void fillRootNodeWithMeshes(Model3DSubFile model3dSubFile,CustomRanAccFile iffRandAccFile) throws IOException{
	List<Mesh> meshList=IffUtils.createJme3MeshPartsListFrom3DSubfile(model3dSubFile, iffRandAccFile);
	
	Material mat = new Material(assetManager,
	          "Common/MatDefs/Misc/Unshaded.j3md");  // create
	mat.setColor("Color", ColorRGBA.Gray);
	
	List<Geometry> geomList= new ArrayList<Geometry>();
	
	//Creates the Geometrys List
	int i=0;
	Geometry geom;
	for(Mesh mesh: meshList){
		geom=new Geometry("Part"+i,mesh);
		i+=1;
		geom.setMaterial(mat);
		geomList.add(geom);
	}
	
	//Create a node to manage all the parts as a group
	Node modelNode= new Node("Model3dNode");
	
	//Attach the Geometrys to the root node
	for(Geometry geometry: geomList){
		modelNode.attachChild(geometry);
	}
	
	System.out.println("modelNode world translation: "+modelNode.getWorldTranslation().toString());
	
	
	
	//Clear the rootNode end guiNode from other results
	guiNode.detachAllChildren();
	
	
	//Atach the Model3DNode to the rootNode
	rootNode.attachChild(modelNode);
	
	Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom2 = new Geometry("Box", b);  // create cube geometry from the shape
 
    geom2.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom2); 
    System.out.println("fillRootNodeWithMeshes: "+rootNode.getChildren().toString());
}






/* (non-Javadoc)
 * @see com.jme3.app.SimpleApplication#simpleUpdate(float)
 */
@Override
public void simpleUpdate(float tpf) {
	// TODO Auto-generated method stub
	super.simpleUpdate(tpf);
}







public void valueChanged(TreeSelectionEvent e) {
	// TODO Auto-generated method stub
	
	//Clear the scene
	for(Spatial spatial:rootNode.getChildren()){
		if(spatial.getName()=="Model3dNode"){
			rootNode.detachChild(spatial);
		}
	}
	
	//Returns the last path element of the selection.
	//This method is useful only when the selection model allows a single selection.
	    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
	                       uiWindow.tree.getLastSelectedPathComponent();

	    if (node == null)
	    //Nothing is selected.  
	    return;
	    Object nodeInfo = node.getUserObject();
	    
	    if (node.isLeaf()) {
	        IffBaseSubFile subFile = (IffBaseSubFile)nodeInfo;
	        
	        
	      //if is an instance of Model3dSubfile draws the model
			if(subFile instanceof Model3DSubFile){
				try {
					fillRootNodeWithMeshes((Model3DSubFile)subFile,uiWindow.inputRandAccFile);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			else if(subFile instanceof TextureInfoSubFile){//if it is instance of TextureModelSubFile draws it
				
			}
	    } 
	
	
	
}

}
[/java]

Maybe you are getting hit by this:
http://hub.jmonkeyengine.org/javadoc/com/jme3/app/Application.html#setPauseOnLostFocus(boolean)
…it defaults to true.

I tested to set it to false and I get this error. What i have to fix to solve it?

I’m pretty confident it’s because the AWT thread is not the same thread as the GL thread, so enqueueing it should work.

I don´t know so much about threads, I suppose that what you mean is that my class for the awt graphic interface is the one causing the error so if I understood you from my jme3 app i mast call enqueue but i don´t know how to build the Callable argument. Should i have to implement the interface Callable in my awt user interface class?

If you want to guide me with the Callable here is my UserInterface code,

[java]
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JToolBar;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JTree;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.IOException;

public class UserInterfaceWindow {

public JFrame frame;
public JTree tree;
public JPanel panel;
public JFileChooser fileChooser;
public IffFile iffFile;
public CustomRanAccFile inputRandAccFile;
/**
 * Create the application.
 */
public UserInterfaceWindow() {
	initialize();
	frame.setVisible(true);
}



/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setBounds(100, 100, 758, 549);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	JToolBar toolBar = new JToolBar();
	frame.getContentPane().add(toolBar, BorderLayout.NORTH);
	
	JButton btnOpenFile = new JButton("Open File");
	btnOpenFile.addActionListener(new OpenButtonClick());
	toolBar.add(btnOpenFile);
	
	JButton button = new JButton("New button");
	toolBar.add(button);
	
	JSplitPane splitPane = new JSplitPane();
	splitPane.setMinimumSize(new Dimension(300, 25));
	frame.getContentPane().add(splitPane, BorderLayout.CENTER);
	
	tree = new JTree();
	tree.setModel(new DefaultTreeModel(
		new DefaultMutableTreeNode("File") {
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			{
			}
		}
	));
	tree.setMinimumSize(new Dimension(200, 0));
	tree.setMaximumSize(new Dimension(200, 64));
	tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	
	splitPane.setLeftComponent(tree);
	
	panel = new JPanel();
	splitPane.setRightComponent(panel);
}



public class OpenButtonClick implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(fileChooser==null)
			setUpFileChooser();


		if(fileChooser.showOpenDialog(frame)==JFileChooser.APPROVE_OPTION){

			try {
				if(inputRandAccFile!=null)
					inputRandAccFile.close();
				inputRandAccFile= new CustomRanAccFile(fileChooser.getSelectedFile(),"rw");
				iffFile=IffUtils.createIffFileInfo(inputRandAccFile);
				UserInterfaceWindow.this.setTreeElements(iffFile,UserInterfaceWindow.this.tree);


			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}



		}
	}
}



public void setTreeElements(IffFile iffFile, JTree tree){


	DefaultMutableTreeNode iffNode= new DefaultMutableTreeNode(iffFile);
	DefaultTreeModel model= new DefaultTreeModel(iffNode, true);


	for(IffBaseSubFile subFile: iffFile.getSubFileList()){

		iffNode.add(new DefaultMutableTreeNode(subFile,false));
	}

	tree.setModel(model);
}


public void setUpFileChooser(){
	fileChooser= new JFileChooser();
	fileChooser.setDialogTitle("Select File");
	FileNameExtensionFilter iffcdfFilter= new FileNameExtensionFilter("IFF/CDF Files","iff","CDF Files","cdf");
	fileChooser.addChoosableFileFilter(iffcdfFilter);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setFileFilter(iffcdfFilter);
}

}[/java]

It’s as simple as this:

[java]
Callable callable = new Callable()
{
public Boolean call()
{
// do stuff…
return true;
}
}
[/java]

What I still don´t understand is what I have to implement into the method call to avoid the error. enqueuing my awt UserInterfaceWindow class from my jme3 app SimpleApp class is supposed to return a value to avoid the error i get. So as my scene changes when the Jtree changes the selected item should i have to return from the call method the Jtree selected item?

I can’t respond with an exact answer to your problem, but adding, removing or modifying anything that is rendered in a jme scene should be done in the Game Logic thread. To do that from another thread (in this case, the AWT thread) you would enque it from your SimpleApplication using a callable. You do not necessarily need the result of the callable - it’s entirely up to you.

So until now if I am right the changes in the scene i made was in the awt thread because I made them using the method valueChanged of the listener: myFileEditor.uiWindow.tree.addTreeSelectionListener(myFileEditor);

I should found a way to make that changes into the Game Logic thread when the Jtree value changes, but I have no idea how can I make this. If anyone knows about it I will be very grateful

@jor1980 said: So until now if I am right the changes in the scene i made was in the awt thread because I made them using the method valueChanged of the listener: myFileEditor.uiWindow.tree.addTreeSelectionListener(myFileEditor);

I should found a way to make that changes into the Game Logic thread when the Jtree value changes, but I have no idea how can I make this. If anyone knows about it I will be very grateful

We told you already. enqueue a callable.

Put simply:
your logic is running on the AWT thread
you cannot modify the scene graph from the AWT thread
you need to get your logic running on the render thread.
the render thread is not the AWT thread.
enqueued Callables are run on the render thread.
the render thread is where it is safe to modify the scene graph
from the AWT thread you will need to enqueue a Callable that modifies the scene graph
that Callable will then be run on the render thread

Which part is unclear?

First of all thanks for all your time and dedication.

All you said is very clear but as I am new on java this is being hard for me. So as I have to create a Callable in my awt thread and from my awt UserInterfaceWindow class I haven´t access to the rootNode of my jme3 SimpleApp instance and as I added a TreeSelectionListener to the Jtree from my SimpleApp instance i could implement the interface Callable into my jme3 SimpleApp and run the method call from the TreeSelectionListener to make that the changes in the scene I made in call method are executed on the jme3 thread. But as i see it doesn´t work so i made it wrong, I was reading again examples with Callable but I still don´t know how to implement it in my code. Here is the code with the changes I made and doesn´t work:

[java]import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.eclipse.swt.widgets.Tree;
import org.omg.CORBA.INITIALIZE;

import com.jme3.app.SettingsDialog.SelectionListener;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;

public class MyFileEditor extends SimpleApplication implements Callable<Boolean>,TreeSelectionListener {
JFileChooser fileChooser;
UserInterfaceWindow uiWindow;

/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub

	EventQueue.invokeLater(new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			
			MyFileEditor myFileEditor= new MyFileEditor();
			myFileEditor.uiWindow= new UserInterfaceWindow();
			myFileEditor.enqueue(myFileEditor);
			myFileEditor.uiWindow.tree.addTreeSelectionListener(myFileEditor);

			AppSettings settings= new AppSettings(true);
			settings.setHeight(myFileEditor.uiWindow.panel.getHeight());
			settings.setWidth(myFileEditor.uiWindow.panel.getWidth());
			myFileEditor.setSettings(settings);
			myFileEditor.createCanvas();

			
			
			JmeCanvasContext ctx = (JmeCanvasContext) myFileEditor.getContext();
			ctx.setSystemListener(myFileEditor);
			Dimension dim = new Dimension(myFileEditor.uiWindow.panel.getWidth(),myFileEditor.uiWindow.panel.getHeight());
			ctx.getCanvas().setPreferredSize(dim);
			myFileEditor.uiWindow.panel.add(ctx.getCanvas());


			myFileEditor.startCanvas();

		}
	});
	
}


public void setUpFileChooser(){
	fileChooser= new JFileChooser();
	fileChooser.setDialogTitle("Select File");
	FileNameExtensionFilter iffcdfFilter= new FileNameExtensionFilter("IFF/CDF Files","iff","CDF Files","cdf");
	fileChooser.addChoosableFileFilter(iffcdfFilter);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setFileFilter(iffcdfFilter);
	
}



@Override
public void simpleInitApp() {
	// TODO Auto-generated method stub
	
	flyCam.setDragToRotate(true);
	/*Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
    geom.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom);  */   
    
    System.out.println("simpleInitApp: "+rootNode.getChildren().toString());
}


//Gets the meshes list from a 3dmodel subfile and attach them to the rootnode
public void fillRootNodeWithMeshes(Model3DSubFile model3dSubFile,CustomRanAccFile iffRandAccFile) throws IOException{
	List&lt;Mesh&gt; meshList=IffUtils.createJme3MeshPartsListFrom3DSubfile(model3dSubFile, iffRandAccFile);
	
	Material mat = new Material(assetManager,
	          "Common/MatDefs/Misc/Unshaded.j3md");  // create
	mat.setColor("Color", ColorRGBA.Gray);
	
	List&lt;Geometry&gt; geomList= new ArrayList&lt;Geometry&gt;();
	
	//Creates the Geometrys List
	int i=0;
	Geometry geom;
	for(Mesh mesh: meshList){
		geom=new Geometry("Part"+i,mesh);
		i+=1;
		geom.setMaterial(mat);
		geomList.add(geom);
	}
	
	//Create a node to manage all the parts as a group
	Node modelNode= new Node("Model3dNode");
	
	//Attach the Geometrys to the root node
	for(Geometry geometry: geomList){
		modelNode.attachChild(geometry);
	}
	
	System.out.println("modelNode world translation: "+modelNode.getWorldTranslation().toString());
	
	
	
	//Clear the rootNode end guiNode from other results
	guiNode.detachAllChildren();
	
	
	//Atach the Model3DNode to the rootNode
	rootNode.attachChild(modelNode);
	
	Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom2 = new Geometry("Box", b);  // create cube geometry from the shape
 
    geom2.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom2); 
    System.out.println("fillRootNodeWithMeshes: "+rootNode.getChildren().toString());
}






/* (non-Javadoc)
 * @see com.jme3.app.SimpleApplication#simpleUpdate(float)
 */
@Override
public void simpleUpdate(float tpf) {
	// TODO Auto-generated method stub
	super.simpleUpdate(tpf);
}







public void valueChanged(TreeSelectionEvent e) {
	// TODO Auto-generated method stub
	
	try {
		this.call();
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	
}


@Override
public Boolean call() throws Exception {
	// TODO Auto-generated method stub
	
	
	//Clear the scene
			for(Spatial spatial:rootNode.getChildren()){
				if(spatial.getName()=="Model3dNode"){
					rootNode.detachChild(spatial);
				}
			}
			
			//Returns the last path element of the selection.
			//This method is useful only when the selection model allows a single selection.
			    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
			                       uiWindow.tree.getLastSelectedPathComponent();

			    if (node == null)
			    //Nothing is selected.  
			    return null;
			    Object nodeInfo = node.getUserObject();
			    
			    if (node.isLeaf()) {
			        IffBaseSubFile subFile = (IffBaseSubFile)nodeInfo;
			        
			        
			      //if is an instance of Model3dSubfile draws the model
					if(subFile instanceof Model3DSubFile){
						try {
							fillRootNodeWithMeshes((Model3DSubFile)subFile,uiWindow.inputRandAccFile);
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
					else if(subFile instanceof TextureInfoSubFile){//if it is instance of TextureModelSubFile draws it
						
					}
			    } 
			
			
	
	return null;
}

}
[/java]

public class MyFileEditor extends SimpleApplication implements Callable

…don’t do that.

Make your own Callable, don’t use application as your callable.

Just some advice… JME is a Java engine. You will struggle every minute if you don’t already know Java reasonably well. It’s not really meant as an “I’m just learning Java/programming” engine so it might work out better if you brush up on Java a bit before tackling the more difficult things.

@pspeed said: public class MyFileEditor extends SimpleApplication implements Callable<Boolean>

…don’t do that.

Make your own Callable, don’t use application as your callable.

Just some advice… JME is a Java engine. You will struggle every minute if you don’t already know Java reasonably well. It’s not really meant as an “I’m just learning Java/programming” engine so it might work out better if you brush up on Java a bit before tackling the more difficult things.

You are right, i am preparing SCJP and now i am starting with threads, but I still don´t know so much about this. As i started my program as a practice to learn now i can´t leave it unfinished.

I made some changes. I create a InnerClass MyCallable to implement into it the changes into the scene, so i create an instance of MyCallable into my SimpleApp class , then enequeue it, and finally into the JTreeSelectionListener i call the method call of myCallable instance to make the changes into the scene, but i must made it again wrong because the changes still are running into the awt thread.

Here is my new code:

[java]import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.eclipse.swt.widgets.Tree;
import org.omg.CORBA.INITIALIZE;

import com.jme3.app.SettingsDialog.SelectionListener;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;

public class MyFileEditor extends SimpleApplication implements TreeSelectionListener {
JFileChooser fileChooser;
UserInterfaceWindow uiWindow;
MyCallable myCallable;

/**
 * @param args
 */
public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	EventQueue.invokeLater(new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			
			MyFileEditor myFileEditor= new MyFileEditor();
			myFileEditor.uiWindow= new UserInterfaceWindow();
			myFileEditor.myCallable=myFileEditor.new MyCallable();
			myFileEditor.enqueue(myFileEditor.myCallable);
			myFileEditor.uiWindow.tree.addTreeSelectionListener(myFileEditor);

			AppSettings settings= new AppSettings(true);
			settings.setHeight(myFileEditor.uiWindow.panel.getHeight());
			settings.setWidth(myFileEditor.uiWindow.panel.getWidth());
			myFileEditor.setSettings(settings);
			myFileEditor.createCanvas();

			
			
			JmeCanvasContext ctx = (JmeCanvasContext) myFileEditor.getContext();
			ctx.setSystemListener(myFileEditor);
			Dimension dim = new Dimension(myFileEditor.uiWindow.panel.getWidth(),myFileEditor.uiWindow.panel.getHeight());
			ctx.getCanvas().setPreferredSize(dim);
			myFileEditor.uiWindow.panel.add(ctx.getCanvas());


			myFileEditor.startCanvas();

		}
	});
	
}


public class MyCallable implements Callable&lt;Boolean&gt;{

	@Override
	public Boolean call() throws Exception {
		// TODO Auto-generated method stub
		
		//Clear the scene
				for(Spatial spatial:rootNode.getChildren()){
					if(spatial.getName()=="Model3dNode"){
						rootNode.detachChild(spatial);
					}
				}
				
				//Returns the last path element of the selection.
				//This method is useful only when the selection model allows a single selection.
				    DefaultMutableTreeNode node = (DefaultMutableTreeNode)
				                       uiWindow.tree.getLastSelectedPathComponent();

				    if (node == null)
				    //Nothing is selected.  
				    return null;
				    Object nodeInfo = node.getUserObject();
				    
				    if (node.isLeaf()) {
				        IffBaseSubFile subFile = (IffBaseSubFile)nodeInfo;
				        
				        
				      //if is an instance of Model3dSubfile draws the model
						if(subFile instanceof Model3DSubFile){
							try {
								fillRootNodeWithMeshes((Model3DSubFile)subFile,uiWindow.inputRandAccFile);
							} catch (IOException e1) {
								// TODO Auto-generated catch block
								e1.printStackTrace();
							}
						}
						else if(subFile instanceof TextureInfoSubFile){//if it is instance of TextureModelSubFile draws it
							
						}
				    } 
				
		
		return null;
	}
	
}

public void setUpFileChooser(){
	fileChooser= new JFileChooser();
	fileChooser.setDialogTitle("Select File");
	FileNameExtensionFilter iffcdfFilter= new FileNameExtensionFilter("IFF/CDF Files","iff","CDF Files","cdf");
	fileChooser.addChoosableFileFilter(iffcdfFilter);
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setFileFilter(iffcdfFilter);
	
}



@Override
public void simpleInitApp() {
	// TODO Auto-generated method stub
	
	flyCam.setDragToRotate(true);
	/*Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    mat.setColor("Color", ColorRGBA.Blue);   // set color of material to blue
    geom.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom);  */   
    
    System.out.println("simpleInitApp: "+rootNode.getChildren().toString());
}


//Gets the meshes list from a 3dmodel subfile and attach them to the rootnode
public void fillRootNodeWithMeshes(Model3DSubFile model3dSubFile,CustomRanAccFile iffRandAccFile) throws IOException{
	List&lt;Mesh&gt; meshList=IffUtils.createJme3MeshPartsListFrom3DSubfile(model3dSubFile, iffRandAccFile);
	
	Material mat = new Material(assetManager,
	          "Common/MatDefs/Misc/Unshaded.j3md");  // create
	mat.setColor("Color", ColorRGBA.Gray);
	
	List&lt;Geometry&gt; geomList= new ArrayList&lt;Geometry&gt;();
	
	//Creates the Geometrys List
	int i=0;
	Geometry geom;
	for(Mesh mesh: meshList){
		geom=new Geometry("Part"+i,mesh);
		i+=1;
		geom.setMaterial(mat);
		geomList.add(geom);
	}
	
	//Create a node to manage all the parts as a group
	Node modelNode= new Node("Model3dNode");
	
	//Attach the Geometrys to the root node
	for(Geometry geometry: geomList){
		modelNode.attachChild(geometry);
	}
	
	System.out.println("modelNode world translation: "+modelNode.getWorldTranslation().toString());
	
	
	
	//Clear the rootNode end guiNode from other results
	guiNode.detachAllChildren();
	
	
	//Atach the Model3DNode to the rootNode
	rootNode.attachChild(modelNode);
	
	Box b = new Box(1, 1, 1); // create cube shape
    Geometry geom2 = new Geometry("Box", b);  // create cube geometry from the shape
 
    geom2.setMaterial(mat);               // set the cube's material
    rootNode.attachChild(geom2); 
    System.out.println("fillRootNodeWithMeshes: "+rootNode.getChildren().toString());
}






/* (non-Javadoc)
 * @see com.jme3.app.SimpleApplication#simpleUpdate(float)
 */
@Override
public void simpleUpdate(float tpf) {
	// TODO Auto-generated method stub
	super.simpleUpdate(tpf);
}







public void valueChanged(TreeSelectionEvent e) {
	// TODO Auto-generated method stub
	
	try {
		this.myCallable.call();
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	
}

}
[/java]

:facepalm:

Why are you calling the callables method directly instead of enqueuing it? Threading seems way beyond your current abilities at the moment, I’m afraid.

This line is just completely wrong:
this.myCallable.call();

What you really want is:
enqueue(myCallable);

But even this:
myFileEditor.enqueue(myFileEditor);

…is a sign that you are completely confused about what is going on.

Thank’s pspeed I changed the code as you said, putting:
enqueue(myCallable);

and deleting the line:
myFileEditor.enqueue(myFileEditor);

Now it seems to work, I can see the scene with no need to click over the render panel, the only thing wrong is that the statsview disappears, I changed PauseOnLostFocus to false but it still disappears

Translated: “Why does the thing in the guiNode disappear when I remove everything from the guiNode?” Hmmm…

You were right. Now it works 100% right. Thank´s for all your time and patience