Example usage for java.awt Graphics2D fillRect

List of usage examples for java.awt Graphics2D fillRect

Introduction

In this page you can find the example usage for java.awt Graphics2D fillRect.

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
    g2d.fillRect(10, 10, getWidth(), getHeight());
    g2d.dispose();/*from  w  ww . ja  v  a2  s. c  o  m*/
}

From source file:Colors.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(12, 16, 116));
    g2d.fillRect(10, 15, 90, 60);

    g2d.setColor(new Color(42, 19, 31));
    g2d.fillRect(130, 15, 90, 60);// w  w  w . j av  a 2s.  c  o m

    g2d.setColor(new Color(70, 7, 23));
    g2d.fillRect(250, 15, 90, 60);

    g2d.setColor(new Color(10, 10, 84));
    g2d.fillRect(10, 105, 90, 60);

    g2d.setColor(new Color(22, 21, 61));
    g2d.fillRect(130, 105, 90, 60);

    g2d.setColor(new Color(21, 98, 69));
    g2d.fillRect(250, 105, 90, 60);

    g2d.setColor(new Color(217, 146, 54));
    g2d.fillRect(10, 195, 90, 60);

    g2d.setColor(new Color(63, 121, 186));
    g2d.fillRect(130, 195, 90, 60);

    g2d.setColor(new Color(131, 121, 11));
    g2d.fillRect(250, 195, 90, 60);

}

From source file:FontHints.java

protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.WHITE);/*from  w ww .  j  ava 2 s  . com*/
    g2d.fillRect(0, 0, getWidth(), getHeight());
    g2d.setColor(Color.BLACK);

    g2d.drawString("Unhinted string", 10, 20);
    if (desktopHints != null) {
        g2d.addRenderingHints(desktopHints);
    }
    g2d.drawString("Desktop-hinted string", 10, 40);
}

From source file:TextureWithBufferedImage.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Rectangle2D rec1, rec2, rec3, rec4, rec5;
    rec1 = new Rectangle2D.Float(25, 25, 75, 150);
    rec2 = new Rectangle2D.Float(125, 25, 10, 75);
    rec3 = new Rectangle2D.Float(75, 125, 125, 75);
    rec4 = new Rectangle2D.Float(25, 15, 12, 75);
    rec5 = new Rectangle2D.Float(15, 50, 15, 15);

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1);
    g2D.setComposite(ac);//from  www. j a v  a 2s . c  o m

    g2D.setStroke(new BasicStroke(5.0f));
    g2D.draw(rec1);
    GradientPaint gp = new GradientPaint(125f, 25f, Color.yellow, 225f, 100f, Color.blue);
    g2D.setPaint(gp);
    g2D.fill(rec2);
    BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bi.createGraphics();
    big.setColor(Color.magenta);
    big.fillRect(0, 0, 5, 5);
    big.setColor(Color.black);
    big.drawLine(0, 0, 5, 5);
    Rectangle r = new Rectangle(0, 0, 5, 5);
    TexturePaint tp = new TexturePaint(bi, r);

    g2D.setPaint(tp);
    g2D.fill(rec3);
    g2D.setColor(Color.green);
    g2D.fill(rec4);
    g2D.setColor(Color.red);
    g2D.fill(rec5);
}

From source file:Test.java

public ApplicationWindow() {
    setBackground(new Color(0, 0, 0, 0));
    this.setSize(200, 200);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel() {
        @Override/*from   www .  ja  v  a  2 s. co m*/
        protected void paintComponent(Graphics gradient) {
            if (gradient instanceof Graphics2D) {
                final int Red = 150;
                final int Green = 150;
                final int Blue = 150;
                Paint paint = new GradientPaint(0.0f, 0.0f, new Color(Red, Green, Blue, 0), getWidth(),
                        getHeight(), new Color(Red, Green, Blue, 255));
                Graphics2D gradient2d = (Graphics2D) gradient;
                gradient2d.setPaint(paint);
                gradient2d.fillRect(0, 0, getWidth(), getHeight());
            }
        }
    };
    this.setContentPane(panel);
}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow);

    g2d.setPaint(gp1);//from  w ww.  j a v a  2s  . co m
    g2d.fillRect(20, 20, 300, 40);

}

From source file:GradientsLine.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 25, Color.green, 2, 2, Color.black, true);

    g2d.setPaint(gp1);/*from ww  w  . ja  v  a  2  s.com*/
    g2d.fillRect(20, 140, 300, 40);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    g2d.setPaint(gp1);//from  w ww .j  a v  a 2  s.co m
    g2d.fillRect(20, 20, 300, 40);

}

From source file:Textures.java

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

    g2d.setPaint(slatetp);/*  www  .  j  a va  2s  .  c  o  m*/
    g2d.fillRect(10, 15, 90, 60);

}

From source file:AffineTransformGetScaleInstance.java

public void paint(Graphics g) {
    AffineTransform atrans = null;

    Graphics2D g2d = (Graphics2D) g;
    atrans = AffineTransform.getScaleInstance(2, 3);

    if (atrans != null)
        g2d.setTransform(atrans);//from  w  w  w.j a  va  2  s.  co  m

    g2d.fillRect(50, 50, 100, 50);
}