Java examples for 2D Graphics:Texture
Stroking or Filling with a Texture
import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; import java.awt.image.BufferedImage; public class Main { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; int x = 10;//from w w w. j a v a2s . com int y = 10; int width = 50; int height = 25; BufferedImage bufferedImage = null; TexturePaint texture = new TexturePaint(bufferedImage, new Rectangle(x, y, width, height)); g2d.setPaint(texture); // Draw shapes...; } }