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

AbstractAction.setEnabled(false) does not disable the action

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: rm29839 Date: 02/02/98


      The setEnabled(boolean b) method of AbstractAction, does not disable the Button it was added to, nor does it prevent the
      actionPerformed method of the AbstractAction implementation from being called.

      source
      ------
      import com.sun.java.swing.*;
      import java.awt.event.*;
      import java.awt.*;

      public class Test extends JFrame {
        public static void main(String [] args) {
          JFrame f = new Test();
          f.pack();
          f.setVisible(true);
        }

        public Test() {
          super("Test");
          _action = new AbstractAction() {
            public void actionPerformed(ActionEvent ev) {
      System.out.println("performed");
            }
            public void setEnabled(boolean b) {
      super.setEnabled(b);
      System.out.println(b);
            }
          };

          JButton button = new JButton("Test");
          button.addActionListener(_action);

          JButton button2 = new JButton("Disable");
          button2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
      System.out.println("Disable");
      _action.setEnabled(false);
            }
          }
      );
          this.getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(button);
          this.getContentPane().add(button2);
        }

        Action _action;
      }

      ----
      javac Test.java
      java Test

      true
      performed
      performed
      Disable
      false
      performed
      (Review ID: 24327)
      ======================================================================

            gsaab Georges Saab
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: