JDK-4485461 : First disabled icon on JButton being cached, not updated if icon changes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.1,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-07-27
  • Updated: 2002-11-16
  • Resolved: 2002-11-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Relates :  
Description

Name: dc32491			Date: 07/27/2001


BOTH:

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)

AND

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

It seems that the very first time an icon is disabled on a JButton, that icon
is cached.  If the JButton's icon is later changed, and the button is disabled
again, the first disabled icon is used instead of a disabled version of the
current icon.  Bug# 4117779 fixed this for JLabel but not JButton.  The
following code demonstrates the problem (substitute .gif files for your own
icons):

==========================================

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class DisabledIconTest {

	public static void main(String[] args) {
		final ImageIcon icon1 = new ImageIcon
("C:/Java/Classes/VerticalRight.gif");
		final ImageIcon icon2 = new ImageIcon
("C:/Java/Classes/VerticalLeft.gif");
		final ImageIcon icon3 = new ImageIcon
("C:/Java/Classes/VerticalCenter.gif");

		final JLabel iconLabel = new JLabel(icon1);
		final JButton iconButton = new JButton(icon1);
		
		final JButton enableButton = new JButton("Enable/Disable");
		enableButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ev) {
				iconButton.setEnabled(!iconButton.isEnabled());
				iconLabel.setEnabled(!iconLabel.isEnabled());
			}
		});

		final JButton switchButton = new JButton("Switch Icon");
		switchButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ev) {
				if (iconButton.getIcon() == icon1) {
					iconButton.setIcon(icon2);
iconLabel.setIcon(icon2);
					return;
				}
				if (iconButton.getIcon() == icon2) {
					iconButton.setIcon(icon3);
					iconLabel.setIcon(icon3);
					return;
				}
				if (iconButton.getIcon() == icon3) {
					iconButton.setIcon(icon1);
					iconLabel.setIcon(icon1);
					return;
				}
			}
		});


		JFrame f = new JFrame("DisabledIconTest");
		f.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER,
5, 5));
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		f.getContentPane().add(iconLabel);
		f.getContentPane().add(iconButton);
		f.getContentPane().add(enableButton);
		f.getContentPane().add(switchButton);
		
		f.pack();
		f.show();
	}

}

==========================================

Steps to reproduce:

1. Run the program, note the icon on both the label and the button.
2. Press the Switch Icon button - the icon changes on both the label and the
button.
3. Press the Enable/Disable button - both label and button are disabled using
the correct icon.
4. Press the Enable/Disable button again to enable the label and button.
5. Press the Switch Icon button.
6. Press the Enable/Disable button.  The label is disabled with the current
icon, but the button is disabled with the same icon from step 3.

This bug is present in both 1.3.1 and the Merlin beta.

This could happen on JMenuItems as well I supppose (I haven't tested it)...
(Review ID: 127496) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b08
2004-06-14

WORK AROUND Name: dc32491 Date: 07/27/2001 We are currently explicitly resetting the disabled icon each time we change the icon, using the GreyFilter: getButton().setDisabledIcon(new ImageIcon(GrayFilter.createDisabledImage (((ImageIcon)newIcon).getImage()))); ======================================================================
2004-06-11

EVALUATION Same applies to JTabbedPane. ###@###.### 2002-11-04
2002-11-04