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

ButtonModel's isArmed(), isPressed() don't work as advertised

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.1
    • client-libs



      Name: boT120536 Date: 07/31/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      A JButton's ButtonModel seems to give incorrect results for the isArmed() and
      isPressed() methods. In particular, isArmed() is true whenever the mouse is
      over the button, and isPressed() is true when the mouse button has been pressed
      but not released. This contradicts the docs at
      http://java.sun.com/j2se/1.3/docs/api/javax/swing/ButtonModel.html.

      If I'm reading the docs correctly, this actually appears to be a problem with
      BasicButtonListener, which calls setArmed(true) during mouseEntered and fails
      to call setArmed(false) during mouseReleased. It also mistakenly calls
      setPressed(true) during mousePressed, and then calls setPressed(false) instead
      of setPressed(true) during mouseReleased.

      Here's an easy test:

      import javax.swing.*;
      import javax.swing.event.*;

      public class Test extends JFrame implements ChangeListener {

         JButton b;
         
         public static void main (String[] args) {
            new Test();
         }

         public Test () {
            b = new JButton("Press me");
            b.addChangeListener(this);
            getContentPane().add(b);
            setSize(100,100);
            setVisible(true);
         }

         public void stateChanged (ChangeEvent e) {
            System.out.println("isArmed "+b.getModel().isArmed());
            System.out.println("isPressed "+b.getModel().isPressed());
            System.out.println("isRollover "+b.getModel().isRollover());
            System.out.println();
         }

      }
      (Review ID: 126082)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: