java.awt
public abstract class Graphics2D extends Graphics
JComponent
- in the
JComponent.paint(Graphics)
method, the incoming
Graphics
should always be an instance of
Graphics2D
;BufferedImage
- see
BufferedImage.createGraphics()
;PrinterJob
- in the
Printable.print(Graphics, PageFormat, int)
method, the incoming
Graphics
should always be an instance of
Graphics2D
.Third party libraries provide support for output to other formats via this API, including encapsulated postscript (EPS), portable document format (PDF), and scalable vector graphics (SVG).
Modifier | Constructor and Description |
---|---|
protected |
Graphics2D() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addRenderingHints(Map<?,?> hints)
Adds/updates the rendering hint.
|
abstract void |
clip(Shape s)
Sets the clip region to the intersection of the current clipping region
and
s . |
abstract void |
draw(Shape shape)
Draws an outline around a shape using the current stroke and paint.
|
void |
draw3DRect(int x,
int y,
int width,
int height,
boolean raised) |
abstract void |
drawGlyphVector(GlyphVector g,
float x,
float y)
Draws a glyph vector at the specified location.
|
abstract void |
drawImage(BufferedImage image,
BufferedImageOp op,
int x,
int y) |
abstract boolean |
drawImage(Image image,
AffineTransform xform,
ImageObserver obs) |
abstract void |
drawRenderableImage(RenderableImage image,
AffineTransform xform) |
abstract void |
drawRenderedImage(RenderedImage image,
AffineTransform xform) |
abstract void |
drawString(AttributedCharacterIterator iterator,
float x,
float y)
Draws an attributed string at the specified location.
|
abstract void |
drawString(AttributedCharacterIterator iterator,
int x,
int y)
Draws an attributed string at the specified location.
|
abstract void |
drawString(String text,
float x,
float y)
Draws a string at the specified location, using the current font.
|
abstract void |
drawString(String text,
int x,
int y)
Draws a string at the specified location, using the current font.
|
abstract void |
fill(Shape shape)
Fills the interior of the specified
shape using the current
paint. |
void |
fill3DRect(int x,
int y,
int width,
int height,
boolean raised)
Fills the specified rectangle with a 3D effect
|
abstract Color |
getBackground()
Returns the color used by the
Graphics.clearRect(int, int, int, int) method. |
abstract Composite |
getComposite()
Returns the current compositing rule.
|
abstract GraphicsConfiguration |
getDeviceConfiguration() |
abstract FontRenderContext |
getFontRenderContext()
Returns the font render context.
|
abstract Paint |
getPaint()
Returns the current paint.
|
abstract Object |
getRenderingHint(RenderingHints.Key hintKey)
Returns the current value of a rendering hint.
|
abstract RenderingHints |
getRenderingHints()
Returns the current rendering hints.
|
abstract Stroke |
getStroke()
Returns the current stroke.
|
abstract AffineTransform |
getTransform()
Returns the current transform.
|
abstract boolean |
hit(Rectangle rect,
Shape text,
boolean onStroke) |
abstract void |
rotate(double theta) |
abstract void |
rotate(double theta,
double x,
double y) |
abstract void |
scale(double scaleX,
double scaleY) |
abstract void |
setBackground(Color color)
Sets the background color (used by the
Graphics.clearRect(int, int, int, int) method). |
abstract void |
setComposite(Composite comp)
Sets the current compositing rule.
|
abstract void |
setPaint(Paint paint)
Sets the paint to be used for subsequent drawing operations.
|
abstract void |
setRenderingHint(RenderingHints.Key hintKey,
Object hintValue)
Adds or updates a hint in the current rendering hints table.
|
abstract void |
setRenderingHints(Map<?,?> hints)
Replaces the current rendering hints with the supplied hints.
|
abstract void |
setStroke(Stroke stroke)
Sets the stroke to be used for subsequent drawing operations.
|
abstract void |
setTransform(AffineTransform transform)
Sets the current transform.
|
abstract void |
shear(double shearX,
double shearY) |
abstract void |
transform(AffineTransform transform)
Sets the current transform to a concatenation of
transform
and the existing transform. |
abstract void |
translate(double tx,
double ty) |
abstract void |
translate(int x,
int y)
Translates this context so that its new origin point is the point
(x, y).
|
clearRect, clipRect, copyArea, create, create, dispose, drawArc, drawBytes, drawChars, drawImage, drawImage, drawImage, drawImage, drawImage, drawImage, drawLine, drawOval, drawPolygon, drawPolygon, drawPolyline, drawRect, drawRoundRect, fillArc, fillOval, fillPolygon, fillPolygon, fillRect, fillRoundRect, finalize, getClip, getClipBounds, getClipBounds, getClipRect, getColor, getFont, getFontMetrics, getFontMetrics, hitClip, setClip, setClip, setColor, setFont, setPaintMode, setXORMode, toString
protected Graphics2D()
public void draw3DRect(int x, int y, int width, int height, boolean raised)
draw3DRect
in class Graphics
public void fill3DRect(int x, int y, int width, int height, boolean raised)
Graphics
fill3DRect
in class Graphics
x
- The X coordinate of the upper left corner of the fill rect.y
- The Y coordinate of the upper left corner of the fill rect.width
- The width of the fill rect.height
- The height of the fill rect.raised
- true
if the rectangle appears raised,
false
if it should appear etched.public abstract void draw(Shape shape)
shape
- the shape (null
not permitted).getStroke()
,
getPaint()
public abstract boolean drawImage(Image image, AffineTransform xform, ImageObserver obs)
public abstract void drawImage(BufferedImage image, BufferedImageOp op, int x, int y)
public abstract void drawRenderedImage(RenderedImage image, AffineTransform xform)
public abstract void drawRenderableImage(RenderableImage image, AffineTransform xform)
public abstract void drawString(String text, int x, int y)
drawString
in class Graphics
text
- the string to draw.x
- the x-coordinate.y
- the y-coordinate.Graphics.setFont(Font)
public abstract void drawString(String text, float x, float y)
text
- the string to draw.x
- the x-coordinate.y
- the y-coordinate.Graphics.setFont(Font)
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y)
drawString
in class Graphics
iterator
- the source of the attributed text.x
- the x-coordinate.y
- the y-coordinate.public abstract void drawString(AttributedCharacterIterator iterator, float x, float y)
iterator
- the source of the attributed text.x
- the x-coordinate.y
- the y-coordinate.public abstract void fill(Shape shape)
shape
using the current
paint.shape
- the shape to fill (null
not permitted).draw(Shape)
,
getPaint()
public abstract GraphicsConfiguration getDeviceConfiguration()
public abstract void setComposite(Composite comp)
comp
- the composite.getComposite()
public abstract void setPaint(Paint paint)
paint
- the paint (null
not permitted).getPaint()
public abstract void setStroke(Stroke stroke)
stroke
- the stroke (null
not permitted).getStroke()
public abstract void setRenderingHint(RenderingHints.Key hintKey, Object hintValue)
hintKey
- the hint key.hintValue
- the hint value.public abstract Object getRenderingHint(RenderingHints.Key hintKey)
hintKey
- the key for the hint.public abstract void setRenderingHints(Map<?,?> hints)
hints
- the hints.addRenderingHints(Map)
public abstract void addRenderingHints(Map<?,?> hints)
hints
- the hints to add or update.public abstract RenderingHints getRenderingHints()
public abstract void translate(int x, int y)
Graphics
public abstract void translate(double tx, double ty)
public abstract void rotate(double theta)
public abstract void rotate(double theta, double x, double y)
public abstract void scale(double scaleX, double scaleY)
public abstract void shear(double shearX, double shearY)
public abstract void transform(AffineTransform transform)
transform
and the existing transform.transform
- the transform.public abstract void setTransform(AffineTransform transform)
null
transform, this method should set the current transform to the
identity transform.transform
- the transform (null
permitted).getTransform()
public abstract AffineTransform getTransform()
setTransform(AffineTransform)
public abstract Paint getPaint()
setPaint(Paint)
public abstract Composite getComposite()
setComposite(Composite)
public abstract void setBackground(Color color)
Graphics.clearRect(int, int, int, int)
method).color
- the color.getBackground()
public abstract Color getBackground()
Graphics.clearRect(int, int, int, int)
method.setBackground(Color)
public abstract Stroke getStroke()
setStroke(Stroke)
public abstract void clip(Shape s)
s
.s
- the shape to intersect with the current clipping region.Graphics.setClip(Shape)
public abstract FontRenderContext getFontRenderContext()
public abstract void drawGlyphVector(GlyphVector g, float x, float y)
g
- the glyph vector.x
- the x-coordinate.y
- the y-coordinate.