Controlling JMEDesktop components from update loop

I have a JLabel component in my JMEDesktop node. I can change the displayed text using label.setText("new text") if that command is issued when the component is created. However I am unable to use the "setText()" command from within my JME update loop. Am I doing something wrong?



This function is called from initGame():

protected void createSwingStuff() {
        desktopPane = jmeDesktop.getJDesktop();
        desktopPane.removeAll();

        final JButton navButton = new JButton( "Set Navigation Path" );
        navButton.setLocation( 450, 3 );
        navButton.setSize(150,20);
        navButton.setBackground(Color.BLACK);
        navButton.setBorder(BorderFactory.createLineBorder(Color.white));
        navButton.setForeground(Color.white);
        navButton.setFocusPainted(false);
        desktopPane.add( navButton );
        navButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                  switchApplication("Firefox");
            }
        } );
       
        final JButton revButton = new JButton( "Reverse Path" );
        revButton.setLocation( 610, 3 );
        revButton.setSize(115,20);
        revButton.setBackground(Color.BLACK);
        revButton.setBorder(BorderFactory.createLineBorder(Color.white));
        revButton.setForeground(Color.white);
        revButton.setFocusPainted(false);
        desktopPane.add( revButton );
        revButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                  //switchApplication("Firefox");
            }
        } );
       
        final JButton helpButton = new JButton( "Help" );
        helpButton.setLocation( 735, 3 );
        helpButton.setSize(50,20);
        helpButton.setBackground(Color.BLACK);
        helpButton.setBorder(BorderFactory.createLineBorder(Color.white));
        helpButton.setForeground(Color.white);
        helpButton.setFocusPainted(false);
        desktopPane.add( helpButton );
        helpButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                  //switchApplication("Firefox");
            }
        } );

        tickerString = new String("Here is the text for the ticker. It needs to be long so that we can see if it wraps. One it wraps to the end it should start over again and come around, then it will be upated by a script based upon the data.");
        ticker = new JLabel( tickerString );
        ticker.setSize( 780,15 );
        ticker.setLocation( 10, 462 );
        desktopPane.add( ticker );
        ticker.setText("new text"); // THIS WORKS TO CHANGE THE TEXT
       
       
        JPanel p = new JPanel(new BorderLayout()); //PREFERRED!
        p.setSize(1024,1024);
        p.setOpaque(false);
        URL imURL = TestHudNode.class.getClassLoader().getResource("datascape/data/textures/GUIFrame.png");
        p.add(new JLabel(new ImageIcon(imURL)));
      desktopPane.add(p);

        desktopPane.repaint();
        desktopPane.revalidate();
    }



And this is called from the update loop:

ticker.setText("new text from update"); // THIS DOESN'T WORK TO CHANGE THE TEXT



The setText() function works from within the initGame function but not when called from update() function. Any ideas?

Thanks!

You should call all swing/awt methods that alter the displayed state from the awt event queue. So use SwingUtils.invokeLater or invokeAndWait to do so. This should also help you with that problem, I think.