public class IconResource extends Object implements Icon
ImageIcon
which takes into account
the display scaling.
Unlike ImageIcon
, this icon knows how to paint itself
in "disabled" (grayed) state.
This class leverages ImageResource
to manage (e.g. cache)
the images used as icons.
AWTUtil.getDisplayScaling()
Modifier and Type | Field and Description |
---|---|
protected String |
description |
protected Image |
disabledImage |
int |
height |
Image |
image |
boolean |
isDoubleSizeImage |
int |
width |
Constructor and Description |
---|
IconResource(Class<?> cls,
String name)
Constructs an icon using specified image resource.
|
IconResource(Class<?> cls,
String name,
Color foreground,
Color background)
Constructs an icon using specified image resource.
|
IconResource(Image image)
Constructs an icon using specified image.
|
IconResource(URL url)
Constructs an icon using specified image URL.
|
IconResource(URL url,
Color foreground,
Color background)
Constructs an icon using specified image URL.
|
Modifier and Type | Method and Description |
---|---|
static Icon |
createDisabledIcon(Icon icon,
JComponent comp)
Create a "disabled" (grayed) icon corresponding to specified icon.
|
String |
getDescription()
Returns the description of this icon.
|
int |
getIconHeight() |
int |
getIconWidth() |
void |
paintIcon(Component c,
Graphics g,
int x,
int y) |
void |
setDescription(String description)
Sets the description of this icon.
|
static void |
setDisabledIcon(AbstractButton button,
Icon icon)
Configures specified button in order to use specified icon as
its disabled icon.
|
static void |
setDisabledIcon(JLabel label,
Icon icon)
Same as
setDisabledIcon(javax.swing.AbstractButton, javax.swing.Icon) but for a JLabel . |
static void |
setDisabledSelectedIcon(AbstractButton button,
Icon icon)
Configures specified button in order to use specified icon as
its disabled selected icon.
|
public final Image image
public final boolean isDoubleSizeImage
public final int width
public final int height
protected String description
protected Image disabledImage
public IconResource(Class<?> cls, String name)
cls
- the image resource belong to this classname
- filename of the image resource. Example: "myicon.png".public IconResource(URL url)
url
- location of the imagepublic IconResource(Image image)
public IconResource(Class<?> cls, String name, Color foreground, Color background)
A bitonal image may be colorized using specified colors.
cls
- the image resource belong to this classname
- filename of the image resource. Example: "myicon.png".foreground
- a new foreground color for the image.
null
means keep original foreground.background
- a new background color for the image.
null
means keep original background.public IconResource(URL url, Color foreground, Color background)
A bitonal image may be colorized using specified colors.
url
- location of the imageforeground
- a new foreground color for the image.
null
means keep original foreground.background
- a new background color for the image.
null
means keep original background.public int getIconWidth()
getIconWidth
in interface Icon
public int getIconHeight()
getIconHeight
in interface Icon
public void setDescription(String description)
Note that this is not automatically done when this icon
is created out of an URL (IconResource(URL)
).
public String getDescription()
null
unless a description has been specified using setDescription(java.lang.String)
.public static void setDisabledIcon(AbstractButton button, Icon icon)
This is needed when the icon is an IconResource
and when the button is configured using an Action
because
otherwise, in this case, the disabled icon is set to null
.
public static void setDisabledIcon(JLabel label, Icon icon)
setDisabledIcon(javax.swing.AbstractButton, javax.swing.Icon)
but for a JLabel
.public static void setDisabledSelectedIcon(AbstractButton button, Icon icon)
This is needed when the icon is an IconResource
and when the button is configured using an Action
because
otherwise, in this case, the disabled icon is set to null
.
public static Icon createDisabledIcon(Icon icon, JComponent comp)
icon
- an iconcomp
- the component which is to use the icon.
May be null
.