JDK-7049934 : JFileChooser on GTK laf in 7-ea does not return multiselection correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86
  • Submitted: 2011-05-31
  • Updated: 2011-06-02
  • Resolved: 2011-06-01
Related Reports
Duplicate :  
Relates :  
Description
JDK 7 ea (build 1.7.0-ea-b143)
Linux (ubuntu 10.10)
GTK look and feel

The bug manifests in NetBeans as
http://netbeans.org/bugzilla/show_bug.cgi?id=197212

The following sample code shows the problem:

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        } catch (Exception ex) {
            Logger.getLogger(JFileChooserTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        JFileChooser chooser = new JFileChooser();
        chooser.setFileHidingEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setMultiSelectionEnabled(true);
        chooser.setDialogTitle("TXT_OpenClasses");
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setApproveButtonText("CTL_SelectCP");
        if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            System.out.println(Arrays.toString(chooser.getSelectedFiles()));;
        }
    }

For single selection it prints out correctly

  [/home/tonda/a.txt]

For three selected files it prints incorrectly

  [/home/tonda/ "a.txt" "b.txt" "c.txt"]

instead of the expected

  [/home/tonda/a.txt, /home/tonda/b.txt, /home/tonda/c.txt]

Comments
EVALUATION There is a problem in the GTKFileChooserUI#getFileName method: it adds unnecessary space at the begin of result in case several files are selected. As the result the BasicFileChooserUI.ApproveSelectionAction#actionPerformed() method cannot determine multiple selection, because it checks the first char on the " character
01-06-2011