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

JButton.isEnabled() return false however the button is enabled

XMLWordPrintable

    • b50
    • x86
    • windows_2000

      FULL PRODUCT VERSION :
      java version "1.4.2_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
      Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      If you create a JButton from an Action that is disabled and then you change the JButtons model to a new DefaultButtonModel() then the button appiers enabled, however, the buttons isEnabled() method returns false.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the snippet as is.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The buttons isEnabled() has to return true, when the button can be pressed (= is enabled)
      ACTUAL -
      The method return false.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.*;
      import javax.swing.*;

      public class MainClass {

        public static void main(String[] args) {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Action a = new AbstractAction("Button") {

            public void actionPerformed(ActionEvent e) {
              System.out.println(((JComponent)e.getSource()).isEnabled());
            }

            public void setEnabled(boolean b) {
              super.setEnabled(false);
            }
          };
          a.setEnabled(false);
          JButton bt = new JButton(a);
          frame.getContentPane().add(bt);
          bt.setModel(new DefaultButtonModel());
          frame.pack();
          frame.show();
        }
      }
      ---------- END SOURCE ----------
      ###@###.### 10/21/04 23:07 GMT

      We have received a fix for this bug from java.net user thulin.
      Attached is the contribution.txt
      ###@###.### 2005-05-05 19:55:09 GMT

            alexp Alexander Potochkin (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: