Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4926884

JFileChooser in details view does not select dir on pressing alphabet

XMLWordPrintable

    • b15
    • generic, x86
    • generic, windows_nt
    • Verified

      Name: pa48320 Date: 09/23/2003


      Steps to reproduce:
      1. Compile and run
          javac -d . DialogTest.java
          java an.bn.DialogTest
      2. Press the button "Open a File". This will bring up the JFileChooser Dialog.
      3. Now select the DETAIL option.
      4. After setting the focus to the files window, press any alphabet and notice that the selection does not move to that file.
      5. Setting to List mode, changing focus to files window and pressing alphabet will highlight that particular file/folder.


      DialogTest.java
      package an.bn;
      import java.io.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.filechooser.*;
      import java.util.StringTokenizer;

      public class DialogTest extends JFrame {
          static private final String newline = "\n";
          JFileChooser fc = null;

          public DialogTest() {
              super("FileChooserDemo");

              //Create the log first, because the action listeners
              //need to refer to it.

              //Create a file chooser
              fc = new JFileChooser();
              fc.setMultiSelectionEnabled(true);
              TextFilter txt = new TextFilter();
              fc.setFileFilter(txt);
              fc.addChoosableFileFilter(txt);
              fc.setCurrentDirectory(new File(System.getProperty("user.dir")));


              //Create the open button
              JButton openButton = new JButton("Open a File...");
              openButton.setMnemonic(openButton.getText().charAt(0));
              openButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      int returnVal = fc.showOpenDialog(null);
                      if (returnVal == JFileChooser.APPROVE_OPTION) {
                          //System.out.println("Approved " + newline);
                          File[] selectedFiles = fc.getSelectedFiles();
                          for ( int i=0; i < selectedFiles.length; i++)
                              System.out.println(" Files Selected:" + selectedFiles[i]
      .toString());
                      }
                      else {
                          System.out.println("Open command cancelled by user." + newli
      ne);
                      }
                      //fc.setSelectedFile(new File(""));
                  }
              });

              //For layout purposes, put the buttons in a separate panel
              JPanel buttonPanel = new JPanel(new FlowLayout());
              buttonPanel.add(openButton);

              //Add the buttons and the log to the frame
              Container contentPane = getContentPane();
              contentPane.add(buttonPanel);
          }
          public static void main(String[] args) {
              StringBuffer tm=new StringBuffer("\"");
              tm.append("THis is new");
              tm.append("\"");
                      System.out.println(tm);
              try {
              System.out.println("LookAndFeel Selected is " + UIManager.getSystemLookA
      ndFeelClassName());
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              }
              catch(Exception e) { System.out.println("An exception is raised by UIMan
      ager.setLookAndFeel\n"); }
              JFrame frame = new DialogTest();

              frame.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }

              });

              frame.pack();
              frame.setVisible(true);
          }

      class TextFilter extends javax.swing.filechooser.FileFilter
      {
              public boolean accept(File f)
              {
                      if ( f.isDirectory() || f.getName().endsWith("txt") || f.getName
      ().endsWith("TXT") )
                              return true;
                      else
                              return false;
              }

              public String getDescription()
              {
                      return "Text Files";
              }
      }

      }
      (Incident Review ID: 208527)
      ======================================================================

            rupashka Pavel Porvatov (Inactive)
            pallenba Peter Allenbach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: