⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e903. listening for changes to the selected file in a jfilechooser dialog.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
A property change event is fired whenever the selected file is changed. However, the selected file can be null if the selected item does not match the selection mode of the chooser. For example, if the selection mode is JFileChooser.FILES_ONLY and a directory is selected, the fired event will have a new value of null. 
Note: SELECTED_FILE_CHANGED_PROPERTY events are fired only if a single item is selected. In particular, if multiple items are selected while multiple-selection mode is enabled, this event is not fired. But if a single item is selected while in multiple-selection mode, this event is fired. 

When in multiple-selection mode, SELECTED_FILES_CHANGED_PROPERTY events are always fired regardless of whether a single or multiple files have been selected. 

    JFileChooser chooser = new JFileChooser();
    
    // Add listener on chooser to detect changes to selected file
    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();
    
                // The selected file should always be the same as newFile
                File curFile = 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();
    
                // Get list of selected files
                // The selected files should always be the same as newFiles
                File[] files = chooser.getSelectedFiles();
            }
        }
    }) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -