aspose file tools*
The moose likes Java in General and the fly likes JNI - Obtaining window handles from AWT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI - Obtaining window handles from AWT" Watch "JNI - Obtaining window handles from AWT" New topic
Author

JNI - Obtaining window handles from AWT

Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Is there a way for a programmer to obtain a window handle from a window created by the AWT. I would like to pass this handle back through a native method and manipulate it with native code.
The platform I am using is Linux/X11.
Frank
Pawel Veselov
Ranch Hand

Joined: Jan 14, 1999
Posts: 165
As far as I know, this can be done with SUN JDK on Solaris/Win32. They have special class called EmbeddedFrame, but this one is in sun.awt.* package, so undocumented and unusable if you are going to use it on any other JDK.
So, the first question is - what JDK are you using ?

With best of best regards, Pawel S. Veselov ( aka Black Angel )
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
I have IBM JDK 1.3, Suns JDK 1.2.2 both for Linux. Incase one is wondering why I would want to obtain a handle to the windows created by the AWT. Well I want to program a window manager for X Windows using Java. I also wanna create a library of native functions that are callable from a Java program which interface to X11 functions and structures.
I am still not sure if its possible to do this but I have been thinking of it lately and how I could implement it. But there are alot of things still to work out.
Frank
Pawel Veselov
Ranch Hand

Joined: Jan 14, 1999
Posts: 165
Okay, JDK (at least one from SUN) will allow you to create an embedded frame, that you can pass your window handle to. So, you should create an actual window, and then JDK will use that window for creating an embedded frame inside it.
This is done with WEmbeddedFrame, that is derivative of an EmbeddedFrame class. I don't know exact details, though, since this classes are sun.awt, and actually sun.awt.<platform>
Frank Hale
Ranch Hand

Joined: Mar 25, 2000
Posts: 230
Thanks Pawel,
There might be an easier method. There is a library called GL4Java which to the best of my knowledge is an implementation of OpenGL in Java which uses a native layer to access the underlying platform dependent OpenGL libs. In this code they get the window handle and there code is open sourced. I think they've pretty much covered what I need so I will just look at there code to see how they did it.
Frank

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNI - Obtaining window handles from AWT