Class VectorIcon
- All Implemented Interfaces:
Serializable, Icon
HiDPI support now exists on MacOS, Windows, and Linux. On MacOS, scaling is 200% for Retina displays, while on Windows 10, the "Change display settings" panel provides the options 100%, 125%, 150%, 175%, 200%, and 225%, as well as the option to enter an arbitrary scaling factor. Non-integral scaling factors can lead to various alignment problems that makes otherwise well-aligned icons look unsharp; this class takes special care to avoid such problems.
Hand-crafted painting code is a good design choice for icons that are simple, ubiqutious in the UI (e.g. part of the Look-and-Feel), or highly parameterized. Swing's native Windows L&F uses this approach for many of its basic icons; see WindowsIconFactory.
When developing new icons, or adjusting existing ones, use the VectorIconTester
utility found in
o.n.swing.tabcontrol/test/unit/src/org/netbeans/swing/tabcontrol/plaf/VectorIconTester.java
to preview and compare icons at different resolutions.
- Since:
- 9.12
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal intfinal intprotected abstract voidpaintIcon(Component c, Graphics2D g, int width, int height, double scaling) Paint the icon at the given width and height.final voidprotected static final intround(double d) protected static final voidsetAntiAliasing(Graphics2D g, boolean enabled) Selectively enable or disable antialiasing during painting.
-
Constructor Details
-
VectorIcon
protected VectorIcon(int width, int height)
-
-
Method Details
-
getIconWidth
public final int getIconWidth()- Specified by:
getIconWidthin interfaceIcon
-
getIconHeight
public final int getIconHeight()- Specified by:
getIconHeightin interfaceIcon
-
setAntiAliasing
Selectively enable or disable antialiasing during painting. Certain shapes may look slightly better without antialiasing, e.g. entirely regular diagonal lines in very small icons when there is no HiDPI scaling. Text antialiasing is unaffected by this setting.- Parameters:
g- the graphics to set antialiasing setting forenabled- whether antialiasing should be enabled or disabled
-
round
protected static final int round(double d) -
paintIcon
-
paintIcon
Paint the icon at the given width and height. The dimensions given are the device pixels onto which the icon must be drawn after it has been scaled up from its originally constant logical dimensions and aligned onto the device pixel grid. Painting onto the suppliedGraphics2Dinstance using whole number coordinates (for horizontal and vertical lines) will encourage sharp and well-aligned icons.The icon should be painted with its upper left-hand corner at position (0, 0). Icons need not be opaque. Due to rounding errors and alignment correction, the aspect ratio of the device dimensions supplied here may not be exactly the same as that of the logical pixel dimensions specified in the constructor.
- Parameters:
c- may be used to get properties useful for painting, as inIcon.paintIcon(Component,Graphics,int,int)g- need not be cleaned up or restored to its previous state after use; will have anti-aliasing already enabled by defaultwidth- the target width of the icon, after scaling and alignment adjustments, in device pixelsheight- the target height of the icon, after scaling and alignment adjustments, in device pixelsscaling- the scaling factor that was used to scale the icon dimensions up to their stated value
-