Mouse Input in JMEDesktop

Hi all.

I've based my GUI implementation on the example found in, together with my BaseGame. The example worked fine, but i'm now having trouble receiving events from my swing components (in the example below, "clicked!" never happens).

I've done quite alot of swing programming before (non jME), but this implementation is giving me problems.

I think it boils down to something pretty simple, like me doing something wrong with the InputHandler(), but i can't seem to get it right…

The initialization itself is almost straight from,, i even left the "button" in there for debug purposes.

public GUIFrame(DisplaySystem display, final InputHandler input)
        setRenderQueueMode( Renderer.QUEUE_ORTHO );
        // create the desktop Quad
        bottomPanel = new UnsafeJMEDesktop( "bottom panel", display.getWidth()-128, 128, guiInput);

        // and attach it to the gui node

        guiInput = new InputHandler();

        bottomPanel.getLocalTranslation().set( bottomPanel.getWidth() / 2, 0, 0);
        SwingUtilities.invokeLater( new Runnable() {
            public void run() {
                bottomPanel.getJDesktop().setBackground( new Color( 0.3f, 0.3f, 0.3f, 1f ) );

                // create a swing button
                final JButton button = new JButton( "click me" );
                // and put it directly on the desktop
                bottomPanel.getJDesktop().add( button );
                // desktop has no layout - we layout ourselfes (could assign a layout to desktop here instead)
                button.setLocation( 20, 0 );
                button.setSize( button.getPreferredSize() );
                // add some actions
                // standard swing action:
                button.addActionListener( new ActionListener() {
                    public void actionPerformed( ActionEvent e ) {
                        // this gets executed in swing thread
                        // alter swing components ony in swing thread!
                        button.setLocation( FastMath.rand.nextInt( 400 ), FastMath.rand.nextInt( 300 ) );
                        System.out.println( "clicked!" );
                } );
                // action that gets executed in the update thread:
                button.addActionListener( new JMEAction( "my action", guiInput ) {
                    public void performAction( InputActionEvent evt ) {
                        // this gets executed in jme thread
                        // do 3d system calls in jme thread only!
                        updateRenderState(); // this call has no effect but should be done in jme thread :)
                guiInput.addAction(new InputAction() {
                public void performAction(InputActionEvent evt) {
            }, InputHandler.DEVICE_MOUSE, InputHandler.BUTTON_ALL,
                    InputHandler.AXIS_NONE, false);
        } );

I then attach the gui node to my PassManager, and do an update every frame since i have some counters and things there that need to be updated.
Here's the update method:

public void update(final float tpf)
        SwingUtilities.invokeLater( new Runnable() {
        public void run()
            updateGeometricState(tpf, true);

If anyone has any ideas or could point me to a thread that would help, i would be most grateful.


I noticed i created guiInput after i used it in bottomPanel().

Doing it before rewarded me with the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
        at java.awt.EventQueue.invokeAndWait(
        at javax.swing.SwingUtilities.invokeAndWait(
        at com.jmex.awt.swingui.JMEDesktop.onMove(
        at com.jmex.awt.swingui.JMEDesktop$XUpdateAction.performAction(
        at com.jme.input.ActionTrigger.performAction(
        at com.jme.input.InputHandler.processTriggers(
        at com.jme.input.InputHandler.update(

Which i guess i related to this thread:

So i'll go on reading there.

Turns out it was StrategicHandler hijacking the mouse cursor.

Lex says in this thread:

Re: Input handler for strategy games