Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

The JColorChooser Class

The JColorChooser class allows you to create a standard dialog with a color palette from which users can select a color.

Properties

In addition to the typical UI properties of Swing components, the color chooser has the properties listed in Table 12-6. The chooserPanels property contains an array of all the chooser panels currently associated with this color chooser. You can get and set the entire array at once or, more commonly, you can add and remove chooser panels using some of the methods described later. The color property contains the currently selected color in the chooser. (This property is just a convenient access point for the selectedColor property of the selectionModel.) The previewPanel property contains the JComponent subclass that previews your color choice. (You can see an example of the default preview panel in Figure 12-7.) The selectionModel property dictates which selection model the chooser uses. The dragEnabled property allows you to drag colors from the chooser to another part of your application, but no transferHandler (inherited from JPanel) is in place to support this feature yet. You would need to supply a handler to make this property meaningful.

Table 12-6. JColorChooser properties

Property

Data type

get

is

set

Default value

accessibleContext

AccessibleContext

·

  

JColorChooser.AccessibleJCol-orChooser( )

chooserPanelsb

AbstractColorChooser-Panel[]

·

 

·

null

color

Color

·

 

·

Color.white

dragEnabled1.4

boolean

·

 

·

false

previewPanelb

JComponent

·

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content