public final class GraphicsUtil
extends java.lang.Object
Constructor and Description |
---|
GraphicsUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
applyRenderingHints(java.awt.Graphics2D g)
This method is intended to use when user settings are not accessible yet.
|
static int |
charWidth(char ch,
java.awt.Font font) |
static int |
charWidth(int ch,
java.awt.Font font) |
static java.lang.Object |
createAATextInfo(java.lang.Object hint) |
static GraphicsConfig |
disableAAPainting(java.awt.Graphics g) |
static java.lang.Object |
getAntialiasingType(javax.swing.JComponent component) |
static GraphicsConfig |
paintWithAlpha(java.awt.Graphics g,
float alpha) |
static java.awt.Graphics |
safelyGetGraphics(java.awt.Component c)
Invoking
Component.getGraphics() disables true double buffering withing JRootPane ,
even if no subsequent drawing is actually performed. |
static void |
setAntialiasingType(javax.swing.JComponent component,
java.lang.Object type) |
static GraphicsConfig |
setupAAPainting(java.awt.Graphics g) |
static void |
setupAntialiasing(java.awt.Graphics g2) |
static void |
setupAntialiasing(java.awt.Graphics g2,
boolean enableAA,
boolean ignoreSystemSettings) |
static void |
setupFractionalMetrics(java.awt.Graphics g) |
static GraphicsConfig |
setupRoundedBorderAntialiasing(java.awt.Graphics g) |
static int |
stringWidth(java.lang.String text,
java.awt.Font font) |
public static void applyRenderingHints(java.awt.Graphics2D g)
public static void setupFractionalMetrics(java.awt.Graphics g)
public static void setupAntialiasing(java.awt.Graphics g2)
public static int stringWidth(java.lang.String text, java.awt.Font font)
public static int charWidth(char ch, java.awt.Font font)
public static int charWidth(int ch, java.awt.Font font)
public static void setupAntialiasing(java.awt.Graphics g2, boolean enableAA, boolean ignoreSystemSettings)
public static GraphicsConfig setupRoundedBorderAntialiasing(java.awt.Graphics g)
public static GraphicsConfig setupAAPainting(java.awt.Graphics g)
public static GraphicsConfig disableAAPainting(java.awt.Graphics g)
public static GraphicsConfig paintWithAlpha(java.awt.Graphics g, float alpha)
public static java.awt.Graphics safelyGetGraphics(java.awt.Component c)
Invoking Component.getGraphics()
disables true double buffering withing JRootPane
,
even if no subsequent drawing is actually performed.
This matters only if we use the default RepaintManager
and swing.bufferPerWindow = true
.
True double buffering is needed to eliminate tearing on blit-accelerated scrolling and to restore frame buffer content without the usual repainting, even when the EDT is blocked.
As a rule of thumb, you should never invoke neither Component.getGraphics()
nor this method unless you really need to perform some drawing.
Under the hood, "getGraphics" is actually "createGraphics" - it creates a new object instance and allocates native resources,
that should be subsequently released by calling Graphics.dispose()
(called from Graphics.finalize()
,
but there's no need to retain resources unnecessarily).
If you need GraphicsConfiguration
, rely on Component.getGraphicsConfiguration()
,
instead of Graphics2D.getDeviceConfiguration()
.
If you absolutely have to acquire an instance of Graphics
, do that via calling this method
and don't forget to invoke Graphics.dispose()
afterwards.
JRootPane.disableTrueDoubleBuffering()
public static java.lang.Object getAntialiasingType(javax.swing.JComponent component)
public static void setAntialiasingType(javax.swing.JComponent component, java.lang.Object type)
public static java.lang.Object createAATextInfo(java.lang.Object hint)