Chapter 12. Chooser Dialogs

Just about every application you write these days needs to have a mechanism for opening and saving files. In the AWT, you can use the FileDialog class, but this is a heavyweight dialog that lacks the flexibility of the Swing components we’ve seen so far. The JFileChooser is Swing’s answer to the FileDialog. The Swing package also contains a helper dialog for choosing colors (a common task during application configuration). We’ll look at both of these dialogs in this chapter.

To get things started, Figure 12-1 shows the class hierarchy of the pieces we’ll be looking at in this chapter.

Class diagram for JFileChooser and JColorChooser

Figure 12-1. Class diagram for JFileChooser and JColorChooser

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.