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

With Swing 1.1.1beta2 JButton no longer generates action when return key pressed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.6, 1.2.2
    • client-libs
    • generic, x86, sparc
    • generic, solaris_2.6, windows_95



      Name: dbT83986 Date: 04/07/99


      Under previous versions of Swing, if a JButton had the current focus, pressing the return
      key would cause the registered ActionListener to be notified. This allowed convenient,
      keyboard input, because text could be entered from a keyboard, using the tab key to
      advance to an "OK button" and the return key could be pressed.

      When I run the same code with the swingall.jar from Swing 1.1.1beta2, the return key no
      longer mimics a mouse click, even when a Jbutton is the component with focus.

      This is on Solaris 2.6 workstation that gives the following output from java -version:
      torch.388> java -version
      java version "1.1.6"
      torch.389> java -fullversion
      java full version "Solaris_JDK_1.1.6_03"

      This behaviour can be reproduced by using the swingall.jar from Swing 1.1 to verify that
      the return keys is the equivalent of a mouse click. Resetting the CLASSPATH to use
      swingall.jar from Swing 1.1.1beta2 and running the same application will demonstrate
      that the buttons will not respond to the return key.

      I used "javac Test.java" to compile, and "java Test" to run.

      Source code:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      class Test implements ActionListener {

              Test() {

                      JFrame jf = new JFrame("Focus Test");
                      JPanel flowPane = new JPanel(new FlowLayout());

                      JButton nButton = new JButton("Do Nothing");
                      nButton.addActionListener(this);
                      nButton.setActionCommand("Nothing");
                      flowPane.add(nButton);

                      JButton OKbutton = new JButton("OK");
                      OKbutton.addActionListener(this);
                      OKbutton.setActionCommand("OK");
                      flowPane.add(OKbutton);

                      jf.getContentPane().add(flowPane);

                      jf.pack();
                      jf.show();
              }


              public void actionPerformed(ActionEvent e) {

                      String command = e.getActionCommand();

                      if (command.equals("Nothing")) {

                              System.out.println("Doing nothing");
                      }

                      if (command.equals("OK")) {

                              System.out.println("OK button pressed");
                              System.exit(1);
                      }
              }

              public static void main(String args[]) {


                      Test test = new Test();
              }
      }
      (Review ID: 56667)
      ======================================================================

      Name: krT82822 Date: 05/30/99


      Until JDK1.2, a Java L&F-JButton that had the focus could be
      activated by hitting the RETURN key. In JDK1.2.2RC, this doesn't
      work anymore (see SwingSet) except when it's the default button.
      If this is supposed to be a L&F design decision, I don't
      understand why it's implemented now, after programs have
      been written that expect the Java L&F to behave like, for
      example, the Windows L&F in that respect.
      (Review ID: 83666)
      ======================================================================

      Name: krT82822 Date: 05/31/99


      Until JDK1.2, a Java L&F-JButton that had the focus could be
      activated by hitting the RETURN key. In JDK1.2.2RC, this doesn't
      work anymore (see SwingSet) except when it's the default button.
      If this is supposed to be a L&F design decision, I don't
      understand why it's implemented now, after programs have
      been written that expect the Java L&F to behave like, for
      example, the Windows L&F in that respect.
      (Review ID: 83666)
      ======================================================================

      Name: skT88420 Date: 06/01/99


      JButton no longer records the enter key as a button press like
      it used to. Possibly the same bug as 4227751.
      (Review ID: 83733)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: