Package swingtree.style
Class ScalableImageIcon
java.lang.Object
javax.swing.ImageIcon
swingtree.style.ScalableImageIcon
- All Implemented Interfaces:
Serializable
,Accessible
,Icon
A wrapper for
ImageIcon
that automatically scales the image to the
current UI.scale()
value defined in the current SwingTree
library context singleton.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
int
Returns the unscaled height of the icon.int
Returns the unscaled width of the icon.int
Exposes the height of the icon, or -1 if the icon does not have a fixed height.
Note that the returned height is dynamically scaled according to the currentUI.scale()
value.int
Exposes the width of the icon, or -1 if the icon does not have a fixed width.
Note that the returned width is dynamically scaled according to the currentUI.scale()
value.getImage()
int
hashCode()
static ScalableImageIcon
A factory method that creates a newScalableImageIcon
that will render the suppliedImageIcon
using the given base size scaled according to the current DPI settings.void
void
toString()
Returns a newScalableImageIcon
that will render the image at the given size.Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImageObserver
-
Method Details
-
of
A factory method that creates a newScalableImageIcon
that will render the suppliedImageIcon
using the given base size scaled according to the current DPI settings.If the given
ImageIcon
is already aScalableImageIcon
, a new instance will be created from the existing one usingwithSize(Size)
.- Parameters:
size
- The size to render the icon at.icon
- The icon to render.- Returns:
- A new
ScalableImageIcon
that will render the image scaled according to the current DPI settings.
-
withSize
Returns a newScalableImageIcon
that will render the image at the given size.
Note that the returned icon will be a new instance and will not affect the current icon.
- Parameters:
size
- The size to render the icon at.- Returns:
- A new
ScalableImageIcon
that will render the image at the given size.
-
getIconWidth
public int getIconWidth()Exposes the width of the icon, or -1 if the icon does not have a fixed width.
Note that the returned width is dynamically scaled according to the currentUI.scale()
value. This is to ensure that the icon is rendered at the correct size according to the current DPI settings. If you want the unscaled width, usegetBaseWidth()
.- Specified by:
getIconWidth
in interfaceIcon
- Overrides:
getIconWidth
in classImageIcon
- Returns:
- The width of the icon, or -1 if the icon does not have a width.
-
getIconHeight
public int getIconHeight()Exposes the height of the icon, or -1 if the icon does not have a fixed height.
Note that the returned height is dynamically scaled according to the currentUI.scale()
value. This is to ensure that the icon is rendered at the correct size according to the current DPI settings. If you want the unscaled height, usegetBaseHeight()
.- Specified by:
getIconHeight
in interfaceIcon
- Overrides:
getIconHeight
in classImageIcon
- Returns:
- The height of the icon, or -1 if the icon does not have a height.
-
getBaseWidth
public int getBaseWidth()Returns the unscaled width of the icon. This is the width of the icon as it was originally loaded and is not affected by the currentUI.scale()
value.
If you want a width that is more suited for rendering according to the current DPI settings, use
getIconWidth()
.- Returns:
- The unscaled width of the icon.
-
getBaseHeight
public int getBaseHeight()Returns the unscaled height of the icon. This is the height of the icon as it was originally loaded and is not affected by the currentUI.scale()
value.
If you want a height that is more suited for rendering according to the current DPI settings, use
getIconHeight()
.- Returns:
- The unscaled height of the icon.
-
paintIcon
-
getImage
-
setImage
-
toString
-
equals
-
hashCode
public int hashCode()
-