Chapter 10.2

4
FILE AND JFILECHOOSER OBJECTS Chapter 10.2:

Transcript of Chapter 10.2

Page 1: Chapter 10.2

FILE AND JFILECHOOSER OBJECTS

Chapter 10.2:

Page 2: Chapter 10.2

The JFileChooser Class

A javax.swing.JFileChooser object allows the user to select a file.

To start the listing from a specific directory:

JFileChooser chooser = new JFileChooser( );

chooser.showOpenDialog(null);

JFileChooser chooser = new JFileChooser("D:/JavaPrograms/Ch12");

chooser.showOpenDialog(null);

Page 3: Chapter 10.2

The JFileChooser Class

Page 4: Chapter 10.2

Getting Info from JFileChooser

int status = chooser.showOpenDialog(null);

if (status == JFileChooser.APPROVE_OPTION) {

JOptionPane.showMessageDialog(null, "Open is clicked");

} else { //== JFileChooser.CANCEL_OPTION

JOptionPane.showMessageDialog(null, "Cancel is clicked");

}

File selectedFile = chooser.getSelectedFile();

File currentDirectory = chooser.getCurrentDirectory();