A texture is a bitmap image applied to a shape : Texture « 2D Graphics GUI « Java

A texture is a bitmap image applied to a shape


import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Textures extends JPanel {
  BufferedImage s;
  public Textures() {
    try {
      s = ImageIO.read(this.getClass().getResource("s.png"));
    } catch (IOException e) {

  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    TexturePaint slatetp = new TexturePaint(s, new Rectangle(0, 0, 90, 60));

    g2d.fillRect(10, 15, 90, 60);


  public static void main(String[] args) {
    JFrame frame = new JFrame("Textures");
    frame.add(new Textures());
    frame.setSize(360, 120);


Related examples in the same category

1.A texture is a bitmap image applied to the surface in computer graphics.
2.TexturePaint DemoTexturePaint Demo
3.Text effect: transparentText effect: transparent
4.Draw text along a curveDraw text along a curve
5.Set Text Attribute
6.Text with a Texture