Files
swing-examples/doc/31_painting.md
2024-03-30 19:57:14 +09:00

1.2 KiB

Painting

@Override
public void paint(Graphics g) {
    final Graphics2D graphics2D = (Graphics2D) g;
	
}
  • component.paint(Graphics)
  • paintComponent(Graphics) -> paintBorder(Graphics) -> paintChildren(Graphics)

Graphics2D

  • drawString()

  • drawImage()

  • drawLine()

  • drawArc() / drawRect() / drawOval() / drawPolygon()

  • draw()

  • fillArc() / fillRect() / fillOval() / fillPolygon()

  • fill()

  • rotate()

  • scale()

  • shear()

  • translate()

Stroke

import java.awt.*;

Graphics2D graphics2D = (Graphics2D) g;
BasicStroke stroke = new BasicStroke(1.f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER,10.f,{10.f},0.f);
graphics2D.setStroke(stroke);

Join style

  • JOIN_BEVEL
  • JOIN_MITER
  • JOIN_ROUND

End-cap style

  • CAP_BUTT
  • CAP_ROUND
  • CAP_SQUARE

Paint

  • Color, GradientPaint, TexturePaint
import java.awt.*;

Paint paint = new GradientPaint(x1,y1,color1,x2,y2,color2);
graphics2D.setPaint(paint);

AffineTransform

  • AffineTransform.getRotateTransform()
  • AffineTransform.getScaleTransform()
  • AffineTransform.getShearTransform()
  • AffineTransform.getTranslateTransform()