JFileChooser: addPropertyChangeListener(PropertyChangeListener listener) : JFileChooser « javax.swing « Java by API






JFileChooser: addPropertyChangeListener(PropertyChangeListener listener)

  

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);
    
  }
}

   
    
  








Related examples in the same category

1.JFileChooser.APPROVE_OPTION
2.JFileChooser.CANCEL_OPTION
3.JFileChooser.DIRECTORIES_ONLY
4.JFileChooser.DIRECTORY_CHANGED_PROPERTY
5.JFileChooser.ERROR_OPTION
6.JFileChooser.SELECTED_FILE_CHANGED_PROPERTY
7.JFileChooser.SELECTED_FILES_CHANGED_PROPERTY
8.JFileChooser: addActionListener(ActionListener l)
9.JFileChooser: addChoosableFileFilter(FileFilter filter)
10.JFileChooser: createDialog(Component parent)
11.JFileChooser: getCurrentDirectory()
12.JFileChooser: getFileSystemView()
13.JFileChooser: getSelectedFile()
14.JFileChooser: getTypeDescription(File f)
15.JFileChooser: isFileHidingEnabled()
16.JFileChooser: setAccessory(JComponent newAccessory)
17.JFileChooser: setApproveButtonMnemonic(char mnemonic)
18.JFileChooser: setApproveButtonText(String approveButtonText)
19.JFileChooser: setApproveButtonToolTipText(String toolTipText)
20.JFileChooser: setControlButtonsAreShown(boolean b)
21.JFileChooser: setCurrentDirectory(File dir)
22.JFileChooser: setFileFilter(FileFilter filter)
23.JFileChooser: setFileHidingEnabled(boolean b)
24.JFileChooser: setFileSelectionMode(int mode)
25.JFileChooser: setFileView(FileView fileView)
26.JFileChooser: setMultiSelectionEnabled(boolean b)
27.JFileChooser: setSelectedFile(File file)
28.JFileChooser: showOpenDialog(Component parent)