Question about updating JmeCanvasContext from a custom JFrame class

I was following the tutorial here:



https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:swing_canvas



… and it works fine. But I wanted to create my own custom JFrame class (which I did). I added a button to the class, and when it is pressed I want the event handler to update the SwingCanvasTest application. So the custom JFrame class is quite simple, and looks like this:



[java]public class NewJFrame extends javax.swing.JFrame

{



private SwingCanvasTest canvas;

private JmeCanvasContext ctx;



/** Creates new form NewJFrame /

public NewJFrame(SwingCanvasTest canvas, JmeCanvasContext ctx)

{

this.canvas = canvas;

this.ctx = ctx;

initComponents();

}



/
* This method is called from within the constructor to

  • initialize the form.
  • WARNING: Do NOT modify this code. The content of this method is
  • always regenerated by the Form Editor.

    */

    @SuppressWarnings(“unchecked”)

    // <editor-fold defaultstate=“collapsed” desc=“Generated Code”>

    private void initComponents() {



    jPanel1 = new javax.swing.JPanel();

    jButton1 = new javax.swing.JButton();



    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);



    jButton1.setText(“jButton1”);

    jButton1.addActionListener(new java.awt.event.ActionListener() {

    public void actionPerformed(java.awt.event.ActionEvent evt) {

    jButton1ActionPerformed(evt);

    }

    });

    jPanel1.add(jButton1);



    jPanel1.add(ctx.getCanvas());



    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 756, Short.MAX_VALUE)

    );

    layout.setVerticalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)

    );



    pack();

    }// </editor-fold>



    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)

    {

    SwingCanvasTest.ROTATE = !SwingCanvasTest.ROTATE;

    ctx.getCanvas().update();

    }



    // Variables declaration - do not modify

    private javax.swing.JButton jButton1;

    private javax.swing.JPanel jPanel1;

    // End of variables declaration

    }

    [/java]



    But the line:



    [java]ctx.getCanvas().update();[/java]



    doesn’t cause the jME canvas to get updated. For instance, all that is showing in the canvas is a blue cube, and when I press the button on the JFrame, I want the cube to rotate… which it does if I then click on the canvas with my mouse. But I just want to force a refresh automatically.



    Any thoughts?

Try Application.setPauseOnLostFocus(false)

Thanks! Exactly what I needed.