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

1.3.1 Escalation: JFileChooser: <Return> Key not working

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.3.1_09
    • 1.3.1
    • client-libs
    • 09
    • sparc
    • solaris_8
    • Verified



      Name: pa48320 Date: 01/22/2003


      1. Take any sample program of JFileChooser
      2. set MotifLookAndFeel by

       UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel
      ");

      3. Run it in Solaris-6

         MotifLookAndFeel dialog box would appear with four buttons..

      4. With <Tab> Key, change the focus to any of the active buttons
      5. Press the <Return> Key..

         Button Press should happen, but nothing happens here..

      6. Hence <Return> Key doesn't work for any of these buttons.

      If one would like to reproduce exactly then please compile the FileChooserDemoMotif.java code ( provided at the end of this description ) and follow following steps..

      A. Run
         java FileChooserDemoMotif
         A Frame will appear with "Open a File..." and "Save a File..."
         buttons..
      B. Click on "Open a File..." Button to launch "Open" FileChooser

      C. With <Tab> Key, change the focus to any of the active buttons
      D. Press the <Return> Key..

         Button Press should happen, but nothing happens here..

      Important Note: This bug doesn't exist with JDK1.4.1,but the problem is "After compilation with JDK1.4.1", it doesn't run in Solaris 6.
      It asks for the library "libXm.so.4". The said library is only available with Solaris 8.

      Here is my Sample program.. Just complile it and run it..

      File : FileChooserDemoMotif.java
      ----------------------------------------------------------------
      import java.io.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.UIManager;
      import java.util.MissingResourceException;


      import javax.swing.JFileChooser;


      public class FileChooserDemoMotif extends JFrame {
          static private final String newline = "\n";

          public FileChooserDemoMotif() {
              super("FileChooserDemoMotif");

              //Create the log first, because the action listeners
              //need to refer to it.
              final JTextArea log = new JTextArea(5,20);
              log.setMargin(new Insets(5,5,5,5));
              log.setEditable(false);
              JScrollPane logScrollPane = new JScrollPane(log);

              //Create a file chooser
              final JFileChooser fc = new JFileChooser();

              //Create the open button
              ImageIcon openIcon = new ImageIcon("images/open.gif");
              JButton openButton = new JButton("Open a File...", openIcon);


              openButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                      fc.setMultiSelectionEnabled(true);

                      //int returnVal = fc.showOpenDialog(FileChooserDemoMotif.this);
                      int returnVal = fc.showOpenDialog(null);

                      if (returnVal == JFileChooser.APPROVE_OPTION) {
                          File file = fc.getSelectedFile();
                          //this is where a real application would open the file.
                          log.append("Opening: " + file.getName() + "." + newline);
                      } else {
                          log.append("Open command cancelled by user." + newline);
                      }
                  }
              });

              //Create the save button
              ImageIcon saveIcon = new ImageIcon("images/save.gif");
              JButton saveButton = new JButton("Save a File...", saveIcon);
              saveButton.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      int returnVal = fc.showSaveDialog(FileChooserDemoMotif.this);

                      if (returnVal == JFileChooser.APPROVE_OPTION) {
                          File file = fc.getSelectedFile();
                          //this is where a real application would save the file.
                          log.append("Saving: " + file.getName() + "." + newline);
                      } else {
                          log.append("Save command cancelled by user." + newline);
                      }
                  }
              });

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

              //Explicitly set the focus sequence.
      // openButton.setNextFocusableComponent(saveButton);
      // saveButton.setNextFocusableComponent(openButton);

              //Add the buttons and the log to the frame
              Container contentPane = getContentPane();
              contentPane.add(buttonPanel, BorderLayout.NORTH);
              contentPane.add(logScrollPane, BorderLayout.CENTER);
          }

          public static void main(String[] args) {

      /*** AKM Added here for Motif Look and Feel ******/
              try {
               String look;
               look = UIManager.getSystemLookAndFeelClassName();
               System.out.println(" AKM System LookAndFeel = "+look);
        // Setting up MotifLookAndFeel
              UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel
      ");
              }
              catch(Exception ex )
              {
                System.out.println(" Failed to set System Look and Feel loading defaul
      t");
              }

      /*** AKM Added above for Motif Look and Feel ******/

               JFrame frame = new FileChooserDemoMotif();

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

              frame.pack();
              frame.setVisible(true);
          }
      }
      ---------------------------------------------------------------------
      (Review ID: 179978)
      ======================================================================

            duke J. Duke
            pallenba Peter Allenbach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: