Error Creating a JMEDesktop

Hello everybody…  :smiley:

I'm trying to create a JME Desktop when I click in an object in my game (using FirstPerson and Pick)…

The JME Desktop shows up, but when I try to interact with it, I got the following error:  :-o


java.lang.IllegalStateException: not in swing thread!
   at com.jmex.awt.swingui.JMEDesktop.dispatchEvent(Unknown Source)
   at com.jmex.awt.swingui.JMEDesktop.setFocusOwner(Unknown Source)
   at com.jmex.awt.swingui.JMEDesktop.setup(Unknown Source)
   at entradas.ChavesPick.performAction(ChavesPick.java:109)
   at com.jme.input.ActionTrigger.performAction(Unknown Source)
   at com.jme.input.InputHandler.processTriggers(Unknown Source)
   at com.jme.input.InputHandler.update(Unknown Source)
   at sistema.SistemaBasico.update(SistemaBasico.java:95)
   at com.jme.app.BaseGame.start(Unknown Source)
   at ecas.Ecas.main(Ecas.java:116)



and here is my code (copy of TestJMEDesktop with less things):

public void performAction(InputActionEvent evt) {
      // TODO Auto-generated method stub
      
      String actionString;
        if ( !evt.getTriggerAllowsRepeats() ) {
               actionString = evt.getTriggerPressed() ? "pressionado" : "solto";
        } else {
               actionString = "baixo";
        }
      
      //se o bot

Have you read the message "not in swing thread!"? It tells you that you have to invoke that method from the swing thread (awt event queue). Use invokeAndWait or invokeLater… and: Have a look at the JMEDesktop tests!

but when I just cull it, the memory was in use by the jmeDesktop…

and, if I just dettach the jmeDesktop from it, and then, if I need to create a new one, attach it again?? is it possible??? when I dettach it from a node, does the memory usage is free???

yeah, now its "working" (only if I use Renderer.QUEUE_TRANSPARENT, otherwise, shows the same error  :|)…

But now I want to make an action to one of th swing buttons. I want that, when I click this button, my JMEDesktop closes…



I think that only adding a "jmeDesktopVariable.dispose()" will work, but when I click the button my game "block" everything… I have to use CTRL+ALT+DEL to exit the game…  :expressionless:



here is the code:  :smiley:

private void createSwingInternalFrame( final JDesktopPane desktopPane, final String title, int x, int y ) {
        final JInternalFrame internalFrame = new JInternalFrame( title );
        if ( title == null ) {
            internalFrame.putClientProperty( "JInternalFrame.isPalette", Boolean.TRUE );
        }
        internalFrame.setLocation( x, y );
        internalFrame.setResizable( false );

        internalFrame.getContentPane().setLayout( new FlowLayout() );
        JButton button1 = new JButton( "button in " + title );
        button1.setMnemonic( 'u' );
        internalFrame.getContentPane().add( button1 );
        internalFrame.getContentPane().add( new JButton( "<html><i>test</i> <big>2</big></html>" ) );
        internalFrame.setVisible( true );
        internalFrame.pack();
        button1.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
               jmeDesktop.dispose(); <


                //showDialog();
            }
        } );



Why my jmeDesktop doesn't just close?

Another Thing: I have a look at JMEDesktop tests and I verified that in TestJMEDesktop, it does not have any calls to SwingUtilities.invokeLater and just work fine, and why in HelloJMEDesktop (that is very more simple) have the call to SwingUtilities.invokeLater???

I GOT THE PROBLEM…  :D  :smiley:



the problem is that, when I clicked to open the JMEDesktop, if I click again, in the area that the pick hits, it opened a new JMEDesktop  }:-@ , that was the problem… now when I click to open the JMEDesktop, I set to stop picking… then, everything goes fine…  :wink:



BUT NOW I WOULD LIKE TO KNOW HOW I MAKE AN ACTION TO A SWING BUTTON to close the JMEDesktop???

How I do this???  :?  :?  :?

I cannot recommend to create and dispose desktops on and on. What about simply hiding (culling) it?