Mixing AWT/Swing and Cocoa-Java

Q: Can Cocoa-Java and AWT/Swing code be mixed in a single application?

A: The mixing of Cocoa-Java and AWT/Swing is neither recommended nor supported by Apple. This includes calls to Cocoa-Java from AWT/Swing based applications, or showing AWT/Swing components from a Cocoa-Java application. While the mixing of these APIs may seem to work, it carries a high risk of causing deadlocks between the Cocoa and AWT event systems.

Additionally, the Cocoa-Java API is deprecated as of Mac OS X Tiger. The Java Native Interface (JNI) is the recommended mechanism for calling platform specific code from AWT/Swing processes on Mac OS X, as it is when using the JDK on any other platform. The JNI can be used to make non-graphical Foundation calls, integrate Application Kit views into an AWT container, or invoke a Java Virtual Machine from an Objectve-C Cocoa app. The details of JNI programming on Mac OS X, as well as an explanation of the risks involved when mixing Cocoa with Java, are explained in Technical Note TN2147.

Document Revision History

DateNotes
2006-10-12Fixed a broken link; noted deprecation of Cocoa-Java.
2006-04-25Added reference to TN2147.
2004-02-26Recommended alternatives to mixing Cocoa-Java and AWT/Swing.

Posted: 2006-10-12


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.