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 | · |
Get Java Swing, 2nd Edition 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.