United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4485461 First disabled icon on JButton being cached, not updated if icon changes
JDK-4485461 : First disabled icon on JButton being cached, not updated if icon changes

Details
Type:
Bug
Submit Date:
2001-07-27
Status:
Resolved
Updated Date:
2002-11-16
Project Name:
JDK
Resolved Date:
2002-11-16
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.1,1.4.0
Fixed Versions:
1.4.2 (mantis)

Related Reports
Duplicate:
Relates:

Sub Tasks

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
EVALUATION

Same applies to JTabbedPane.
###@###.### 2002-11-04
                                     
2002-11-04
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
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis
mantis-b08


                                     
2004-06-14



Hardware and Software, Engineered to Work Together