Java Reference
In-Depth Information
The color property is special in that it has three ways of setting itself:
Directly from a Color
From one integer representing its red-green-blue values combined into one int variable
using the nibble allocation 0xAARRGGBB, where A is for alpha value (and is ignored,
using 255 instead)
From three integers, separating the red, green, and blue color components into three
separate int variables
If you don't use showDialog() , you can customize the JColorChooser before displaying it.
Besides customizing the color property, which is settable in the JColorChooser constructor,
you can customize the component to be displayed in the preview area and the color chooser
panels.
Changing the Preview Panel
It's the responsibility of the ColorChooserComponentFactory class to provide the default
component for the preview area of the JColorChooser . For the standard look and feel types,
the preview panel is in the bottom portion of the color chooser.
If you don't want a preview panel in the color chooser, you must change the previewPanel
property to a component value that isn't null . When the property is set to null , the default
preview panel for the look and feel is shown. Setting the property to an empty JPanel serves the
purpose of not showing the preview panel.
colorChooser.setPreviewPanel(new JPanel());
Figure 9-20 shows what one such color chooser might look like without the preview panel.
Because the JPanel has no size when nothing is in it, this effectively removes the panel.
Figure 9-20. JColorChooser without a preview panel
If you want the preview panel present, but just don't like the default appearance, you can
add your own JComponent to the area. Configuration entails placing your new preview panel in
 
Search WWH ::




Custom Search