Version: 1.2

Posted: 2006-04-12

Build Requirements: Xcode 2.0 or later

Runtime Requirements: Mac OS X 10.4 or later, Java 1.4.2 or later

View Source Code:

Download Sample (“CWCocoaComponent.zip”, 123.9K)
Download Sample (“CWCocoaComponent.dmg”, 182.0K)



Description

This sample uses Apple's CocoaComponent feature to embed an NSColorWell inside a Swing JFrame in place of the standard JColorChooser. An integration layer is set up where changes to the system NSColorPanel are converted to Java AWT events, allowing Java code to utiilize the native color picker for AWT or Swing components. Note the use of EventQueue.invokeLater when firing AWT events to ensure thread safety between Java and Cocoa.

This sample code has been updated to include a project that produces a universal binary. No code changes were required for it to run correctly on Intel-based Macintosh computers. See Technical Note 2147 for more details on using CocoaComponent.

Document Revision History

Date Notes
2006-04-12Updated compiler options to generate 1.4 compatible bytecode.
2005-08-10Updated to produce a universal binary. No code changes were required. Added smarter JNIEnv management.
2005-06-01Native color picker Integration for AWT/Swing applications using NSColorWell and NSColorPanel

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.