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

REGRESSION: default button does not render the button pressed action

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      hopper
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description



      Name: rmT116609 Date: 12/12/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VN (build 1.4.0-beta3-b84, mixed mode)

      Buttons behave differently if they are clicked directly with a mouse or through
      the setDefaultButton feature. In one instance, "button pressed" is painted.
      In the other, it is not. It is disorienting to a user not see the "button
      pressed" painted. This is true for Metal , Motif and Windows Look & Feel.


      To test - run this program. Click on the button and then hit the enter key and
      see the difference.

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

      public class DefaultButton extends JFrame {

        private int count = 0;
        private JButton button = new JButton("Hit ... Me");
        private JLabel label = new JLabel("Hit Count = " + count);
        private JPanel contentPane = new JPanel();

        public DefaultButton () {
          super("Button Frame");

          setContentPane(contentPane);
          contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
          contentPane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
          contentPane.add(button);
          contentPane.add(label);

          this.getRootPane().setDefaultButton(button);
          button.setPreferredSize(new Dimension(100, 35));

          button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              count++;
              label.setText("Hit Count = " + count);
            }
          });
          this.pack();
          this.setVisible(true);
          this.setLocation(200,200);
        }

        public static void main(String[] args) {
           try {
       // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
       // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
           } catch (Exception e) {
             e.printStackTrace();
           }
           new DefaultButton();
        }
      }
      (Review ID: 137186)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shickeysunw Shannon Hickey (Inactive)
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: