public class BasicGraphicsUtils extends Object
Constructor | Description |
---|---|
BasicGraphicsUtils() |
Modifier and Type | Method | Description |
---|---|---|
static void |
drawBezel(Graphics g,
int x,
int y,
int w,
int h,
boolean isPressed,
boolean isDefault,
Color shadow,
Color darkShadow,
Color highlight,
Color lightHighlight) |
Draws a bezel.
|
static void |
drawDashedRect(Graphics g,
int x,
int y,
int width,
int height) |
Draws dashed rectangle.
|
static void |
drawEtchedRect(Graphics g,
int x,
int y,
int w,
int h,
Color shadow,
Color darkShadow,
Color highlight,
Color lightHighlight) |
Draws an etched rectangle.
|
static void |
drawGroove(Graphics g,
int x,
int y,
int w,
int h,
Color shadow,
Color highlight) |
Draws a groove.
|
static void |
drawLoweredBezel(Graphics g,
int x,
int y,
int w,
int h,
Color shadow,
Color darkShadow,
Color highlight,
Color lightHighlight) |
Draws a lowered bezel.
|
static void |
drawString(Graphics g,
String text,
int underlinedChar,
int x,
int y) |
Draw a string with the graphics
g at location (x,y)
just like g.drawString would. |
static void |
drawString(JComponent c,
Graphics2D g,
String string,
float x,
float y) |
Draws the given string at the specified location using text properties
and anti-aliasing hints from the provided component.
|
static void |
drawStringUnderlineCharAt(Graphics g,
String text,
int underlinedIndex,
int x,
int y) |
Draw a string with the graphics
g at location
(x , y )
just like g.drawString would. |
static void |
drawStringUnderlineCharAt(JComponent c,
Graphics2D g,
String string,
int underlinedIndex,
float x,
float y) |
Draws the given string at the specified location underlining
the specified character.
|
static String |
getClippedString(JComponent c,
FontMetrics fm,
String string,
int availTextWidth) |
Clips the passed in string to the space provided.
|
static Insets |
getEtchedInsets() |
Returns the amount of space taken up by a border drawn by
drawEtchedRect() |
static Insets |
getGrooveInsets() |
Returns the amount of space taken up by a border drawn by
drawGroove() |
static Dimension |
getPreferredButtonSize(AbstractButton b,
int textIconGap) |
Returns the preferred size of the button.
|
static float |
getStringWidth(JComponent c,
FontMetrics fm,
String string) |
Returns the width of the passed in string using text properties
and anti-aliasing hints from the provided component.
|
public static void drawEtchedRect(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
g
- an instance of Graphics
x
- an X coordinatey
- an Y coordinatew
- a widthh
- a heightshadow
- a color of shadowdarkShadow
- a color of dark shadowhighlight
- a color highlightinglightHighlight
- a color of light highlightingpublic static Insets getEtchedInsets()
drawEtchedRect()
public static void drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight)
g
- an instance of Graphics
x
- an X coordinatey
- an Y coordinatew
- a widthh
- a heightshadow
- a color of shadowhighlight
- a color highlightingpublic static Insets getGrooveInsets()
drawGroove()
public static void drawBezel(Graphics g, int x, int y, int w, int h, boolean isPressed, boolean isDefault, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
g
- an instance of Graphics
x
- an X coordinatey
- an Y coordinatew
- a widthh
- a heightisPressed
- is component pressedisDefault
- is default drawingshadow
- a color of shadowdarkShadow
- a color of dark shadowhighlight
- a color highlightinglightHighlight
- a color of light highlightingpublic static void drawLoweredBezel(Graphics g, int x, int y, int w, int h, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
g
- an instance of Graphics
x
- an X coordinatey
- an Y coordinatew
- a widthh
- a heightshadow
- a color of shadowdarkShadow
- a color of dark shadowhighlight
- a color highlightinglightHighlight
- a color of light highlightingpublic static void drawString(Graphics g, String text, int underlinedChar, int x, int y)
g
at location (x,y)
just like g.drawString
would. The first occurrence
of underlineChar
in text will be underlined.
The matching algorithm is not case sensitive.g
- an instance of Graphics
text
- a textunderlinedChar
- an underlined charx
- an X coordinatey
- an Y coordinatepublic static void drawStringUnderlineCharAt(Graphics g, String text, int underlinedIndex, int x, int y)
g
at location
(x
, y
)
just like g.drawString
would.
The character at index underlinedIndex
in text will be underlined. If index
is beyond the
bounds of text
(including < 0), nothing will be
underlined.g
- Graphics to draw withtext
- String to drawunderlinedIndex
- Index of character in text to underlinex
- x coordinate to draw aty
- y coordinate to draw atpublic static void drawDashedRect(Graphics g, int x, int y, int width, int height)
g
- an instance of Graphics
x
- an X coordinatey
- an Y coordinatewidth
- a width of rectangleheight
- a height of rectanglepublic static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
b
- an instance of AbstractButton
textIconGap
- a gap between text and iconpublic static void drawString(JComponent c, Graphics2D g, String string, float x, float y)
c
- the component that will display the string, may be nullg
- the graphics context, must not be nullstring
- the string to display, may be nullx
- the x coordinate to draw the text aty
- the y coordinate to draw the text atNullPointerException
- if the specified g
is null
public static void drawStringUnderlineCharAt(JComponent c, Graphics2D g, String string, int underlinedIndex, float x, float y)
The underlinedIndex
parameter points to a char value
(Unicode code unit) in the given string.
If the char value specified at the underlined index is in
the high-surrogate range and the char value at the following index is in
the low-surrogate range then the supplementary character corresponding
to this surrogate pair is underlined.
No character is underlined if the index is negative or greater
than the string length (index < 0 || index >= string.length())
or if the char value specified at the given index
is in the low-surrogate range.
c
- the component that will display the string, may be nullg
- the graphics context, must not be nullstring
- the string to display, may be nullunderlinedIndex
- index of a a char value (Unicode code unit)
in the string to underlinex
- the x coordinate to draw the text aty
- the y coordinate to draw the text atNullPointerException
- if the specified g
is null
getStringWidth(javax.swing.JComponent, java.awt.FontMetrics, java.lang.String)
public static String getClippedString(JComponent c, FontMetrics fm, String string, int availTextWidth)
c
- the component, may be nullfm
- the FontMetrics used to measure the string width, must be
obtained from the correct font and graphics. Must not be null.string
- the string to clip, may be nullavailTextWidth
- the amount of space that the string can be drawn innull
or emptyNullPointerException
- if the specified fm
is null
getStringWidth(javax.swing.JComponent, java.awt.FontMetrics, java.lang.String)
public static float getStringWidth(JComponent c, FontMetrics fm, String string)
null
, returns zero.c
- the component, may be nullfm
- the FontMetrics used to measure the advance string width, must
be obtained from the correct font and graphics. Must not be null.string
- the string to get the advance width of, may be nullnull
stringNullPointerException
- if the specified fm
is null
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2017, Oracle and/or its affiliates. 500 Oracle Parkway
Redwood Shores, CA 94065 USA. All rights reserved.
DRAFT 9-internal+0-adhoc.mlchung.jdk9-jdeps