Listening for Changes to the Selected File in a JFileChooser Dialog
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.util.Arrays; import javax.swing.JFileChooser; public class Main { public static void main(String[] argv) { JFileChooser chooser = new JFileChooser(); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) { JFileChooser chooser = (JFileChooser) evt.getSource(); File oldFile = (File) evt.getOldValue(); File newFile = (File) evt.getNewValue(); System.out.println(oldFile); System.out.println(newFile); System.out.println(chooser.getSelectedFile()); } else if (JFileChooser.SELECTED_FILES_CHANGED_PROPERTY.equals(evt.getPropertyName())) { JFileChooser chooser = (JFileChooser) evt.getSource(); File[] oldFiles = (File[]) evt.getOldValue(); File[] newFiles = (File[]) evt.getNewValue(); Arrays.toString(oldFiles); Arrays.toString(newFiles); File[] files = chooser.getSelectedFiles(); Arrays.toString(files); } } }); chooser.setVisible(true); } }