RFR: 4834298: JFileChooser.getSelectedFiles() failed with multi-selection and double-click [v3]

Jayathirth D V jdv at openjdk.org
Thu Sep 8 10:21:44 UTC 2022


On Tue, 6 Sep 2022 11:14:49 GMT, Tejesh R <tr at openjdk.org> wrote:

>> JFileChooser.getSelectedFiles() failed to retrieve files with multi-selection and double-click. This occurs when a single file is selected then enable multi-selection then select the same file through mouse double-click(Two file chooser dialogs used before and after multi-selection enabled). SelectedFiles are updated when a change in files/directory selection is done or when selection is made through keyboard selection. In this case since a single file is selected before multi-selection is enabled and same file is selected again without changing the selection index/directory, leaving selected Files un-updated. 
>> **Proposed Fix** : Whenever Multi-Selection is enabled check if any files are selected, if yes update the selected Files of JFileChoooser.
>
> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updated based on review comments

src/java.desktop/share/classes/sun/swing/FilePane.java line 1766:

> 1764:                 selectedFiles[0] = getFileChooser().getSelectedFile();
> 1765:             }
> 1766: 

Is this problem seen only when single file is selected? What happens when more than one file is selected?
By default, is MultiSelection enabled on JfileChooser?

In FilePane.java, i see that get/setSelectedFiles() is exclusively used when multi-selection mode is enabled and get/setSelectedFile() is used when multi-selection is not enabled. Using getSelectedFile() to change the state when multi-selection is enabled might introduce state corruption issues in other scenarios.

-------------

PR: https://git.openjdk.org/jdk/pull/9996



More information about the client-libs-dev mailing list