Java Swing and native windows

Hi,

I’m posting this here because the Mac OS X proficient dudes most probably sit here anyway…

My problem lies in the creation of an LWJGL native window under Mac OS X. Now, if I just create the window, it appears, but behaves wrongly. That is, it cannot be highlighted or moved, and no application icon or system menu appears for the program.

Now, if I create and dispose a swing window just before creating the LWJGL native window, everything is fine, and a java icon appears along with a default system menu. So, How does java register itself with Mac OS X to be a “GUI” app thereby getting the special treatment I need?

  • elias

Don’t know anything about it, but until someone comes along with a real answer, this may help out:

http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL/chap4/chapter_4_section_2.html#//apple_ref/doc/uid/TP30000163/CJECBHJE

It looks like a simple open-a-Cocoa-window-and-get-OpenGL-to-draw tutorial. Even if it’s not what you’re after it may give you an idea of where to start.

Unfortunately all those programs will behave correctly when placed in a Mac application bundle (as Project Builder will do correctly), but not when the code is brought into a JNI library :confused:

  • elias

This call before init()ing the LWJGL window is enough:

Toolkit.getDefaultToolkit();

So initializing the toolkit is enough to trigger the “I’m a graphical application” voodoo.

Anybody knows if the java for mac source is available? :smiley:

  • elias

Well, here’s what SWT does on MacOSX-Carbon:

JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_carbon_OS_CreateNewWindow
      (JNIEnv *env, jclass that, jint arg0, jint arg1, jobject arg2, jintArray arg3)
{
      Rect _arg2, *lparg2=NULL;
      jint *lparg3=NULL;
      jint rc;

      DEBUG_CALL("CreateNewWindow\n")

      if (arg2) lparg2 = getRectFields(env, arg2, &_arg2);
      if (arg3) lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL);
      rc = (jint)CreateNewWindow((WindowClass)arg0, (WindowAttributes)arg1, (const Rect *)lparg2, (WindowRef *)lparg3);
      if (arg2) setRectFields(env, arg2, lparg2);
      if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0);
      return rc;
}

CreateNewWindow appears to be documented here:

http://developer.apple.com/documentation/Carbon/Reference/Window_Manager/wind_mgr_ref/function_group_6.html#//apple_ref/c/func/CreateNewWindow

And useful links from there (sorry for the long links) are “Window Attribute Constants”:

http://developer.apple.com/documentation/Carbon/Reference/Window_Manager/wind_mgr_ref/constant_1.html#//apple_ref/doc/uid/TP30000176/C006478

and “Window Attributes”:

http://developer.apple.com/documentation/Carbon/Reference/Window_Manager/wind_mgr_ref/constant_2.html#//apple_ref/doc/uid/TP30000176/C015461

Are you passing the right flags to the CreateNewWindow function?

If you get no joy from any of that, you might want to look at how wxWindows does it:

I’ve got a rather good understanding of the Mac API from surfing the developer connection for hours trying to locate the problem. So the window creation code is ok I guess. Also, the problem is that the window alters it’s behaviour depending on the launch conditions.

But diggin’ in SWT is a good one. Hope I’ll find the right stuff in there.

  • elias

SWT apps apparantly have the same problem(!). Except Eclipse because it’s packaged in a special way. I merely want to emulate the capability of the vm to enable GUI mode on demand (you can’t demand that LWJGL apps be packaged in a native Mac bundle).

  • elias