-
Bug
-
Resolution: Won't Fix
-
P4
-
1.4.1, 1.4.2, 6
-
generic, x86
-
generic, windows_2000
Name: jk109818 Date: 02/18/2003
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
(The problem should affect all platforms)
A DESCRIPTION OF THE PROBLEM :
According to the documentation for
AbstractButton.getDisabledIcon():
"If no disabled icon has been set, the button constructs one
from the default icon."
Looking at the source, however, this only happens when the
default icon is an instance of ImageIcon. In other cases,
getDisabledIcon() returns null, and the icon on the disabled
button does not change.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached program as follows:
java t foo.gif
Where foo.gif is a small image file, to be used as the
default image for the buttons in the program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected results:
The displayed window should show two grayed buttons.
Actual results:
Only the first button is grayed, although both buttons are
disabled.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class t
{
public static void main(String[] args)
{
new t().doIt(args[0]);
}
private void doIt(String file)
{
try {
JFrame f = new JFrame("test");
JPanel p = new JPanel(new FlowLayout());
JButton b1 = new JButton();
b1.setIcon(new ImageIcon(file));
b1.setEnabled(false);
JButton b2 = new JButton();
b2.setIcon(new MyIcon(file));
b2.setEnabled(false);
p.add(b1);
p.add(b2);
f.getContentPane().add(p);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.pack();
f.show();
}catch (Exception e) {
e.printStackTrace();
}
}
public class MyIcon implements Icon
{
private ImageIcon ic;
public MyIcon(String s)
{
ic = new ImageIcon(s);
}
public int getIconWidth()
{
return ic.getIconWidth();
}
public int getIconHeight()
{
return ic.getIconHeight();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
ic.paintIcon(c, g, x, y);
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Use ImageIcons or make your own Icon implementation extend
ImageIcon. In my case, I was able to do the latter.
(Review ID: 181351)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
(The problem should affect all platforms)
A DESCRIPTION OF THE PROBLEM :
According to the documentation for
AbstractButton.getDisabledIcon():
"If no disabled icon has been set, the button constructs one
from the default icon."
Looking at the source, however, this only happens when the
default icon is an instance of ImageIcon. In other cases,
getDisabledIcon() returns null, and the icon on the disabled
button does not change.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached program as follows:
java t foo.gif
Where foo.gif is a small image file, to be used as the
default image for the buttons in the program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected results:
The displayed window should show two grayed buttons.
Actual results:
Only the first button is grayed, although both buttons are
disabled.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class t
{
public static void main(String[] args)
{
new t().doIt(args[0]);
}
private void doIt(String file)
{
try {
JFrame f = new JFrame("test");
JPanel p = new JPanel(new FlowLayout());
JButton b1 = new JButton();
b1.setIcon(new ImageIcon(file));
b1.setEnabled(false);
JButton b2 = new JButton();
b2.setIcon(new MyIcon(file));
b2.setEnabled(false);
p.add(b1);
p.add(b2);
f.getContentPane().add(p);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
f.pack();
f.show();
}catch (Exception e) {
e.printStackTrace();
}
}
public class MyIcon implements Icon
{
private ImageIcon ic;
public MyIcon(String s)
{
ic = new ImageIcon(s);
}
public int getIconWidth()
{
return ic.getIconWidth();
}
public int getIconHeight()
{
return ic.getIconHeight();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
ic.paintIcon(c, g, x, y);
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Use ImageIcons or make your own Icon implementation extend
ImageIcon. In my case, I was able to do the latter.
(Review ID: 181351)
======================================================================
- duplicates
-
JDK-5090711 Icons for Disabled JMenuItems don't follow specs
-
- Closed
-
- relates to
-
JDK-4969419 All generated disabled icons should have same look with Ocean
-
- Resolved
-
-
JDK-5021082 Metal L&F: JFileChooser disabled toolbar buttons should use grayed icons
-
- Closed
-