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

Custom Icon (javax.swing.Icon) not disabled when JButton is disabled

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: client-libs

      Description

      FULL PRODUCT VERSION :
      Tested on:

      JDK 1.6.0_07
      JDK 1.6.0_05

      ADDITIONAL OS VERSION INFORMATION :
      Tested in Vista x64 and Windows XP.

      A DESCRIPTION OF THE PROBLEM :

      When creating a custom icon class (one that extends javax.swing.Icon) and adding it to a JButton, the icon is not disabled when the JButton is disabled i.e. when JButton.setEnabled(false) is called.

      The exact same image when added to an ImageIcon works correctly when added to a JButton.

      Code to reproduce the problem is listed below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a class that implements Icon. Instantiate a JButton and pass in the custom icon as the displayable image.

      Set the JButton to disabled by invoking JButton.setEnabled(false).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the disabled JButton that used the custom icon class to have the image be grayed out (per the way the ImageIcon JButton worked).

      This does not occur.
      ACTUAL -

      The JButton that was disabled and used the custom icon class did not display the disabled icon as expected. The icon image on the disabled JButton still looked "active".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

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

      public class TestIcon extends JFrame
      {
      public class CustomIcon implements Icon
      {
      private Image mImage;

      public CustomIcon(Image image)
      {
      mImage = image;
      }

      public int getIconWidth()
      {
      return mImage.getWidth(null);
      }

      public int getIconHeight()
      {
      return mImage.getHeight(null);
      }

      public void paintIcon(Component c, Graphics g, int x, int y)
      {
      g.drawImage(mImage, x, y, c);
      }
      }


      public TestIcon()
      {
      Image image = Toolkit.getDefaultToolkit().getImage(".\\image.gif");

      ImageIcon imageIcon = new ImageIcon(image);
      CustomIcon customIcon = new CustomIcon(image);

      JPanel panel = new JPanel();
      panel.setLayout(new GridLayout(1, 4));


      JButton button = new JButton(imageIcon);
      panel.add(button);

      button = new JButton(imageIcon);
      button.setEnabled(false);
      panel.add(button);

      button = new JButton(customIcon);
      panel.add(button);

      button = new JButton(customIcon);
      button.setEnabled(false);
      panel.add(button);

      Container cp = this.getContentPane();
      cp.add(panel);

      this.pack();
      this.setVisible(true);
      }



      public static void main(String[] args)
      {
      new TestIcon();
      }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :

      Did not find a workaround to this problem.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: