Login  Register

Re: GLHandler refuse to init

Posted by Xerxes Rånby on Feb 10, 2014; 11:27pm
URL: https://forum.jogamp.org/SOLVED-GLHandler-refuse-to-init-tp4031535p4031536.html

Teapot wrote
The program runs normally but GLHandler will not init and its display method will never get invoked unless I tab to desktop then back. Complete source: http://pastebin.com/SaYYAuxP

I'm pretty sure something broke somewhere, but what?
The GLCanvas components will only initialize after they have become visible.

your application needs to follow the swing coding guidelines:
1. all swing components has to be manipulated from the "event dispatch thread"
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
rewrite your main to use the SwingUtils like this in order to satisfy this Swing/AWT "event patch thread" rule:
  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new test();
        }
    }
  }

2. after you have added canvas using add(canvas); you need to re-validate the JFrame in order for it to relayout its components and make the newly added canvas visible.
you can re-validate the JFrame by calling its pack() or validate() method.
http://docs.oracle.com/javase/6/docs/api/java/awt/Container.html#validate%28%29 
This should make the component visible and initialize the JogAmp GLCanvas.


If you want to make your application more portable then i recommend you to stop using all swing & awt components and simply use a JogAmp NEWT GLWindow.

Cheers
Xerxes