Example usage for java.awt Graphics2D fill

List of usage examples for java.awt Graphics2D fill

Introduction

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

Prototype

public abstract void fill(Shape s);

Source Link

Document

Fills the interior of a Shape using the settings of the Graphics2D context.

Usage

From source file:MyCanvas.java

public void draw(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Draw the pie chart
    Arc2D.Float arc = new Arc2D.Float(Arc2D.PIE);
    arc.setFrame(140, 200, 67, 46);/*from   www. j  a  v a 2 s  . c  om*/
    arc.setAngleStart(45);
    arc.setAngleExtent(270);
    g2.setColor(Color.gray);
    g2.draw(arc);
    g2.setColor(Color.red);
    g2.fill(arc);
    g2.setColor(Color.black);
    g2.drawString("Arc2D.PIE", 140, 190);
}

From source file:TextLayoutWithMouseClickDrag.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = AffineTransform.getTranslateInstance(rx, ry);

    Shape hilight = layout.getLogicalHighlightShape(hit1, hit2);
    hilight = at.createTransformedShape(hilight);
    g2.setColor(Color.lightGray);
    g2.fill(hilight);

    g2.setColor(Color.black);//from   ww w .  jav a  2  s  .  co  m
    layout.draw(g2, rx, ry);

    Shape[] caretShapes = layout.getCaretShapes(hit1);
    Shape caret = at.createTransformedShape(caretShapes[0]);
    g2.setColor(caretColor);
    g2.draw(caret);
}

From source file:AnimationTester.java

public synchronized void paintComponent(Graphics g) {
    if (values == null)
        return;/*from   www .j a  v  a 2 s  .c  om*/
    Graphics2D g2 = (Graphics2D) g;
    int width = getWidth() / values.length;
    for (int i = 0; i < values.length; i++) {
        Double v = values[i];
        Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, v);
        if (v == marked1 || v == marked2)
            g2.fill(bar);
        else
            g2.draw(bar);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.0, w, h, 0.0, 60.0, Arc2D.CHORD);
    System.out.println(arc.contains(new Rectangle(5, 6, 20, 20)));
    g2.draw(arc);/*www.j av  a 2s  .  co m*/

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE);

    g2.fill(arc);

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN);

    g2.draw(arc);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0);
    Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0);

    Area a1 = new Area(e1);
    Area a2 = new Area(e2);

    a1.subtract(a2);/*from ww w.ja  v a2 s .  c om*/

    a1.transform(new AffineTransform());

    g2.setColor(Color.orange);
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("subtract", 20, 140);

}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.5, w, h, 0.0, 60.0, Arc2D.CHORD);
    arc.setAngleStart(new Point(3, 4));
    g2.draw(arc);/*from  w w  w . j  a  v  a2  s .  c o  m*/

    Arc2D arc1 = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE);
    arc.setArc(arc1);
    g2.fill(arc);

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN);

    g2.draw(arc);
}

From source file:OptionDialogTest.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1);
    g2.setPaint(Color.YELLOW);//  www. j a va  2 s .c om
    g2.fill(rect);
    g2.setPaint(Color.BLUE);
    g2.draw(rect);
}

From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java

private void drawSelectionRubberBand(Graphics2D g) {
    g.setPaint(getSelectionBackground());
    g.draw(rubberBand);/*w ww.j a  va 2s .  c  o  m*/
    g.setComposite(ALPHA);
    g.setPaint(selectionColor);
    g.fill(rubberBand);
}

From source file:SwingTimerBasedAnimationScaleRotate.java

public void paint(Graphics g) {
    int h = getHeight();
    int w = getWidth();

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2d.translate(w / 2, h / 2);//from   www  .j  ava  2 s. c o  m
    g2d.rotate(angle);
    g2d.scale(scale, scale);

    g2d.fill(r);
}

From source file:AreaAdd.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    double halfWdith = getSize().width / 2;
    double halfHeight = getSize().height / 2;

    circle.setFrame(halfWdith - 25, halfHeight, 50.0, 50.0);
    oval.setFrame(halfWdith - 19, halfHeight - 20, 40.0, 70.0);
    circ = new Area(circle);
    ov = new Area(oval);
    circ.add(ov);//from   w  ww .  ja v a2s.c o  m
    g2.fill(circ);
}