JDK-4922507 : JFileChooser works with keyboard incorrectly sometimes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2003-09-15
  • Updated: 2004-02-18
  • Resolved: 2004-01-16
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.
Other
5.0 b35Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

Name: iaR10016			Date: 09/15/2003


Filed By : J2SE-SQA [###@###.###
JDK      : JDK1.5.0-b19, JDK1.4.2-b28
Platform : all

JFileChooser works with keyboard incorrectly sometimes.

Please, run doit.sh script below:

--------- test.java ---------
import javax.swing.*;
public class test {
  public static void main(String[] args) {
      (new JFileChooser("./dir1")).showOpenDialog(new JFrame());
      System.out.println("OK!");
   }
}
---------- doit.sh ----------
#!/bin/bash

mkdir dir1
mkdir dir1/dir11
mkdir dir1/dir11/dir111
mkdir dir1/dir11/dir112
mkdir dir1/dir12
mkdir dir1/dir13
mkdir dir1/dir14
mkdir dir1/dir15
mkdir dir1/dir15/dir151
mkdir dir1/dir15/dir152

JDK="/net/linux-15/export/home/java/jdk1.5.0/linux"
export PATH=.:$PATH
$JDK/bin/javac test.java
$JDK/bin/java test
-----------------------------

JFileChooser appears after the test class loading. Current directory is "dir1".

Please, do the following steps to reproduce the failure:

1. Move the focus to the file list panel (do not use mouse!) - you need to press <Tab> key
    10 times to do it. Now focus is in the file panel. There is no files selected, so the
    cursor is not highlighted.

2. After the pressing <Down> key, "dir11" directory becomes selected. This is correct
    expected behavior.

3. Move the cursor to "dir15" pressing <Down> key several times, then press <Enter> and
    enter "dir15" directory.

4. Try to play with keyboard when you are inside "dir15" directory: you will see that
    it is impossible to select any files in the file list using keyboard now.

Please, note that all is OK with "dir11" directory - if you enter it, all is OK there
and file list can correctly get focus without mouse. It happens because "dir11" is the
first directory in the "dir1" file list and 1 is less then the number of the files in
"dir11" folder (2), whereas "dir15" is fifth file in "dir1" files list and the file
number in "dir15" (2) is less then 5.

======================================================================

Comments
EVALUATION Changed subcategory to classes_swing since this appears to be a problem with the JFileChooser UI. ###@###.### 2003-09-15 Name: pzR10082 Date: 09/26/2003 Looks like a bug. ###@###.### ====================================================================== Name: keR10081 Date: 11/12/2003 This happens because we do not set correct initial selection index on changing directory, leaving it as it was in previous directory, so it can appear in a nonexistent position, thus disappearing. Suggested fix corrects this. ###@###.### ======================================================================
03-09-2004

SUGGESTED FIX Name: keR10081 Date: 11/12/2003 ------- BasicFileChooserUI.java ------- *** /tmp/sccs.0xaOTI Wed Nov 12 15:34:01 2003 --- BasicFileChooserUI.java Wed Nov 12 15:33:58 2003 *************** *** 118,123 **** --- 118,124 ---- // The accessoryPanel is a container to place the JFileChooser accessory component private JPanel accessoryPanel = null; private Handler handler; + private JList list; public BasicFileChooserUI(JFileChooser b) { *************** *** 159,170 **** } protected void installListeners(JFileChooser fc) { - propertyChangeListener = createPropertyChangeListener(fc); - if(propertyChangeListener != null) { - fc.addPropertyChangeListener(propertyChangeListener); - } - fc.addPropertyChangeListener(getModel()); - InputMap inputMap = getInputMap(JComponent. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); SwingUtilities.replaceUIInputMap(fc, JComponent. --- 160,165 ---- *************** *** 171,176 **** --- 166,177 ---- WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap); ActionMap actionMap = getActionMap(); SwingUtilities.replaceUIActionMap(fc, actionMap); + + propertyChangeListener = createPropertyChangeListener(fc); + if(propertyChangeListener != null) { + fc.addPropertyChangeListener(propertyChangeListener); + } + fc.addPropertyChangeListener(getModel()); } InputMap getInputMap(int condition) { *************** *** 387,392 **** --- 388,394 ---- protected MouseListener createDoubleClickListener(JFileChooser fc, JList list) { + this.list = list; return new Handler(list); } *************** *** 736,741 **** --- 738,744 ---- } public void actionPerformed(ActionEvent e) { JFileChooser fc = getFileChooser(); + if (list != null) list.setSelectedIndex(0); fc.setCurrentDirectory(fc.getFileSystemView().getHomeDirectory()); } } *************** *** 771,776 **** --- 774,780 ---- // Ok, use f as is } getFileChooser().setCurrentDirectory(dir); + list.setSelectedIndex(0); return; } } *************** *** 879,884 **** --- 883,889 ---- if (isDir && isTrav && !isDirSelEnabled) { chooser.setCurrentDirectory(selectedFile); + if (list != null) list.setSelectedIndex(0); return; } else if ((isDir || !isFileSelEnabled) && (!isDir || !isDirSelEnabled) ====================================================================== Name: keR10081 Date: 12/17/2003 *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/sun/swing/FilePane.java- Mon Dec 1 18:44:14 2003 --- FilePane.java Mon Dec 1 18:40:26 2003 *************** *** 1224,1230 **** } public void clearSelection() { ! if (listSelectionModel != null) { listSelectionModel.clearSelection(); } } --- 1224,1231 ---- } public void clearSelection() { ! if (listSelectionModel != null && list != null) { ! list.setSelectedIndex(0); listSelectionModel.clearSelection(); } } ###@###.### ======================================================================
03-09-2004

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b35 tiger-beta2 VERIFIED IN: tiger-beta2
03-09-2004