JDK-6972078 : Can not select single directory with GTKLookAndFeel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2010-07-26
  • Updated: 2022-11-17
  • Resolved: 2022-11-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b24Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Linux onnies 2.6.32-23-generic #37-Ubuntu SMP Fri Jun 11 07:54:58 UTC 2010 i686 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When using a JFileChooser with the file selection mode FILES_AND_DIRECTORIES and multiSelection enabled, it is impossible to select a single directory when using GTKLookAndFeel.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Please run the attached test case, select a single directory and press the button "Print selected Files". Please notice that fileChooser.getSelectedFiles() just returns an empty array in this case.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected that fileChooser.getSelectedFiles() returns the selected directory.
ACTUAL -
I saw that fileChooser.getSelectedFiles() returns an empty array.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GTKFileChooserTest extends JFrame {

    public GTKFileChooserTest() {
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new BorderLayout());

        final JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fileChooser.setMultiSelectionEnabled(true);
        fileChooser.setControlButtonsAreShown(false);
        getContentPane().add(fileChooser, BorderLayout.CENTER);

        JButton getSelectedFilesButton = new JButton();
        getSelectedFilesButton.setText("Print selected Files");
        getSelectedFilesButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                System.out.println("selected files:");
                for (java.io.File file : fileChooser.getSelectedFiles()) {
                    System.out.println(file);
                }
            }
        });
        getContentPane().add(getSelectedFilesButton, BorderLayout.SOUTH);
        pack();
    }

    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        } catch (Exception ex) {
        }
        EventQueue.invokeLater(new Runnable() {

            public void run() {
                new GTKFileChooserTest().setVisible(true);
            }
        });
    }
}

---------- END SOURCE ----------

Comments
Changeset: 4a68210d Author: Abhishek Kumar <abhiscxk@openjdk.org> Committer: Tejesh R <tr@openjdk.org> Date: 2022-11-10 14:11:52 +0000 URL: https://git.openjdk.org/jdk/commit/4a68210d9f6c59ec4289b2e2412a1ae0df17fd81
10-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/10866 Date: 2022-10-26 04:34:24 +0000
26-10-2022

Issue is re-producible in Linux for GTK LAF. Analysis under progress.
14-10-2022