@Override
    protected void createContext(AppSettings settings) {
        // In case canvas is not visible, we still take framerate
        // from settings to prevent "100% CPU usage"
        frameRate = settings.getFrameRate();
        allowSwapBuffers = settings.isSwapBuffers();

        try {
            if (renderable.get()) {
                if (!runningFirstTime) {
                    // because the display is a different opengl context
                    // must reset the context state.
                    if (!USE_SHARED_CONTEXT) {
                        renderer.cleanup();
                    }
                }

                // if the pbuffer is currently active,
                // make sure to deactivate it
                destroyPbuffer();

                if (Keyboard.isCreated()) {
                    Keyboard.destroy();
                }

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {}

                Display.setVSyncEnabled(settings.isVSync());
                Display.setParent(canvas);

                if (USE_SHARED_CONTEXT) {
                    Display.create(acquirePixelFormat(false), pbuffer);
                } else {
                    Display.create(acquirePixelFormat(false));
                }
                if (settings.isOpenCLSupport()) {
                    initOpenCL();
                }

                renderer.invalidateState();
            } else {
                // First create the pbuffer, if it is needed.
                makePbufferAvailable();
            }

            // At this point, the OpenGL context is active.
            if (runningFirstTime) {
                // THIS is the part that creates the renderer.
                // It must always be called, now that we have the pbuffer workaround.
                initContextFirstTime();
                runningFirstTime = false;
            }
        } catch (LWJGLException ex) {
            listener.handleError("Failed to initialize OpenGL context", ex);
            // TODO: Fix deadlock that happens after the error (throw runtime exception?)
        }
    }
This is called: 1) When the context thread starts 2) Any time the canvas becomes displayable
again. In the first call of this method, OpenGL context is not ready yet. Therefore, OpenCL
context cannot be created. The second call of this method is done after "simpleInitApp" is
called. Therefore, OpenCL won't be available in "simpleInitApp" if Canvas/Swing is used. To use
OpenCL with Canvas/Swing, you need to use OpenCL in the rendering loop "simpleUpdate" and check
for "context.getOpenCLContext()!=null".
jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java