JFileChooser
Swing, part of the Java Foundation Classes, provides a much more
sophisticated and useful file chooser component written in pure Java,
javax.swing.JFileChooser
:
public class JFileChooser extends JComponent implements Accessible
JFileChooser is not an independent, free-standing
window like FileDialog. Instead, it is a component
you can add to your own frame, dialog, or other container or window.
You can, however, ask the JFileChooser class to
create a modal dialog just for your file chooser. Figure 13.3 shows a file chooser embedded in a
JFrame window with the Metal look and
feel.[26] Of course, like all Swing
components, the exact appearance depends on the look and feel
currently selected.

Figure 13-3. A JFileChooser with the Metal look and feel
For the most part, the file chooser works as you expect, especially if you’re accustomed to Windows. You select a file with the mouse. Double-clicking the filename or pressing the Open button returns the currently selected file. You can change which files are displayed by selecting different filters from the pop-up list of choosable file filters. All the components have tooltips to help users who are a little thrown by an unfamiliar look and feel. One difference between a Swing file chooser and a standard, native chooser may surprise you. While double-clicking on a directory will open the directory as you expect, selecting a directory ...
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.
Read now
Unlock full access