19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

(a)<br />

(b)<br />

Figure 38.19<br />

An instance of JColorChooser is displayed in a dialog box with the OK,<br />

Cancel, and Reset but<strong>to</strong>ns.<br />

The showDialog method creates an instance of JDialog with three<br />

but<strong>to</strong>ns, OK, Cancel, and Reset, <strong>to</strong> hold a JColorChooser object,<br />

as shown in Figure 38.19(a). The method displays a modal dialog.<br />

If the user clicks the OK but<strong>to</strong>n, the method dismisses the dialog<br />

and returns the selected color. If the user clicks the Cancel<br />

but<strong>to</strong>n or closes the dialog, the method dismisses the dialog and<br />

returns null.<br />

JColorChooser consists of a tabbed pane and a color preview<br />

panel. The tabbed pane has three tabs for choosing colors using<br />

Swatches, HSB, and RGB, as shown in Figure 38.19(b). The preview<br />

panel shows the effect of the selected color.<br />

NOTE: JColorChooser is very flexible. It allows you <strong>to</strong><br />

replace the tabbed pane or the color preview panel with<br />

cus<strong>to</strong>m <strong>com</strong>ponents. The default tabbed pane and the color<br />

preview panel are sufficient. You rarely need <strong>to</strong> use<br />

cus<strong>to</strong>m <strong>com</strong>ponents.<br />

38.9 JFileChooser<br />

The javax.swing.JFileChooser class displays a dialog box from<br />

which the user can navigate through the file system and select<br />

files for loading or saving, as shown in Figure 38.20.<br />

Figure 38.20<br />

The Swing JFileChooser shows files and direc<strong>to</strong>ries, and enables the<br />

user <strong>to</strong> navigate through the file system visually.<br />

Like JColorChooser, JFileChooser is a lightweight <strong>com</strong>ponent<br />

inherited from JComponent. It can be added <strong>to</strong> any container if<br />

30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!