O'Reilly logo

Java® and Mac OS® X by T. Gene Davis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 JFrames and other Java Containers. 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 CocoaComponents 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 CocoaComponents.

I explain JNI on OS X more thoroughly in Chapter 9. Other chapters also use JNI as ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required