This discussion is archived
3 Replies Latest reply: Oct 31, 2012 3:59 AM by 965060 RSS

JNI problems moving from JDK 1.6 to 1.7.

965060 Newbie
Currently Being Moderated
Hiya

I have a java app which creates a Canvas and uses JNI to pass the HWND to native Win32 code (it's used as a render target). Everything was working fine and dandy until I updated to Java 7 (1.7.0)...

Previously, all mouse wheel and keyboard presses over the Canvas were passed directly to the native HWND. Since updating to 1.7.0, however, these events get passed to the Canvas object and never reach my native code :-( Mouse clicks and movement work as before.

Has anyone else seen this behaviour? Any suggestions on how to work around this issue?

Regards,

--Jon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  • 1. Re: JNI problems moving from JDK 1.6 to 1.7.
    gimbal2 Guru
    Currently Being Moderated
    Fix seems obvious: in stead of relying on the windows messaging, facilitate it yourself through the JNI interface by propagating events you catch on the java side to the native logic. That will probably incur a slight performance hit of course, but you lose the dependency on internal mechanisms.
  • 2. Re: JNI problems moving from JDK 1.6 to 1.7.
    965060 Newbie
    Currently Being Moderated
    Thanks for the reply. Yes, what you describe would work around the problem, but I thought of that as a 'brute force' approach :-) My application has been working the same way for years, so I'd prefer to try and find a simpler fix for it.

    After a bit of research, I think the issue could be due to changes in how focus is handled for JDK 7:

    http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/awt.html#gdcqp

    so I'll investigate this first.

    Regards,

    --Jon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  • 3. Re: JNI problems moving from JDK 1.6 to 1.7.
    965060 Newbie
    Currently Being Moderated
    For the record, here's how I solved the problem:

    The Canvas that was used for native rendering didn't receive any mouse events; they appeared to be lost somehow. Although my native CView-derived class didn't receive focus events, I noticed that CView::OnMouseActivate() was still being called when I clicked on the Canvas. I overrode this function and added a call to SetFocus(), which was enough to cause mouse wheel and keyboard messages to be passed to my native View.

    Regards,

    --Jon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points