Chapter 8. Embedding Cocoa Components
The application menu, the Dock, the Help Viewer, and other features are all available to your Java application. If you want your application to look native, you can make it look and feel like any Cocoa or Carbon application.
You can do more than just make your Java application look and feel like Cocoa and Carbon applications. The com.apple.eawt
package contains one class that allows you to embed native GUI widgets and interfaces directly into your JFrame
s and other Java Container
s. This class is the CocoaComponent
class.
The CocoaComponent
integrates with native Objective-C GUI elements. The elements are Objective-C NSView
objects. The native code you write instantiates an NSView
and then passes the NSView
reference back to the Java CocoaComponent
. You place the CocoaComponent
in the Java Container
of your choice.
Using CocoaComponent
s requires knowledge of JNI, C, and Objective-C. Also, an understanding of the Cocoa framework is useful. I explain the JNI, C, and Objective-C code used in this and other chapters. I do not attempt to thoroughly teach C or Objective-C. Rather, I attempt to give you a basic understanding of C and Objective-C as it applies to implementing CocoaComponent
s.
I explain JNI on OS X more thoroughly in Chapter 9. Other chapters also use JNI as ...
Get Java® and Mac OS® X now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.