Example usage for java.awt Graphics setColor

List of usage examples for java.awt Graphics setColor

Introduction

In this page you can find the example usage for java.awt Graphics setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:Splash.java

public void paint(Graphics g) {
    im.paintIcon(this, g, 0, 0);
    g.setColor(Color.green);
    g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 7, 7);
}

From source file:AlignLabels.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    Color oldColor = g.getColor();
    g.setColor(color);
    g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
    g.setColor(oldColor);/*from   w  w  w .  j  a  v  a2 s. co  m*/
}

From source file:ImageBorderHack.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g.setColor(Color.white);
    g.fillRect(x, y, width, height);//  w  w  w  .j  av a  2s.  c o  m

    Graphics2D g2 = (Graphics2D) g;

    int tlw = topLeftImage.getWidth(null);
    int tlh = topLeftImage.getHeight(null);
    int tcw = topCenterImage.getWidth(null);
    int tch = topCenterImage.getHeight(null);
    int trw = topRight.getWidth(null);
    int trh = topRight.getHeight(null);

    int lcw = leftCenterImage.getWidth(null);
    int lch = leftCenterImage.getHeight(null);
    int rcw = rightCenterImage.getWidth(null);
    int rch = rightCenterImage.getHeight(null);

    int blw = bottomLeftImage.getWidth(null);
    int blh = bottomLeftImage.getHeight(null);
    int bcw = bottomCenterImage.getWidth(null);
    int bch = bottomCenterImage.getHeight(null);
    int brw = bottomRightImage.getWidth(null);
    int brh = bottomRightImage.getHeight(null);

    fillTexture(g2, topLeftImage, x, y, tlw, tlh);
    fillTexture(g2, topCenterImage, x + tlw, y, width - tlw - trw, tch);
    fillTexture(g2, topRight, x + width - trw, y, trw, trh);

    fillTexture(g2, leftCenterImage, x, y + tlh, lcw, height - tlh - blh);
    fillTexture(g2, rightCenterImage, x + width - rcw, y + trh, rcw, height - trh - brh);

    fillTexture(g2, bottomLeftImage, x, y + height - blh, blw, blh);
    fillTexture(g2, bottomCenterImage, x + blw, y + height - bch, width - blw - brw, bch);
    fillTexture(g2, bottomRightImage, x + width - brw, y + height - brh, brw, brh);
}

From source file:ColorVariousObjects.java

public void paint(Graphics g) {
    Color c1 = new Color(255, 100, 100);
    Color c2 = new Color(100, 255, 100);
    Color c3 = new Color(100, 100, 255);

    g.setColor(c1);
    g.drawLine(0, 0, 100, 100);/*from w  w w.j  av a2 s .  c o m*/
    g.drawLine(0, 100, 100, 0);

    g.setColor(c2);
    g.drawLine(40, 25, 250, 180);
    g.drawLine(75, 90, 400, 400);

    g.setColor(c3);
    g.drawLine(20, 150, 400, 40);
    g.drawLine(5, 290, 80, 19);

    g.setColor(Color.red);
    g.drawOval(10, 10, 50, 50);
    g.fillOval(70, 90, 140, 100);

    g.setColor(Color.blue);
    g.drawOval(190, 10, 90, 30);
    g.drawRect(10, 10, 60, 50);

    g.setColor(Color.cyan);
    g.fillRect(100, 10, 60, 50);
    g.drawRoundRect(190, 10, 60, 50, 15, 15);
}

From source file:org.kalypso.ogc.gml.map.widgets.advanced.utils.GeometryPainter.java

public static void drawPolygon(final IMapPanel mapPanel, final Graphics g, final Polygon polygon,
        final Color border, final Color fill) {
    final LineString ring = polygon.getExteriorRing();
    int[] x = new int[] {};
    int[] y = new int[] {};
    for (int i = 0; i < ring.getNumPoints(); i++) {

        try {/*from w  w  w  .ja  v  a  2  s . c o m*/
            final Point p = ring.getPointN(i);
            final GM_Point gmp = (GM_Point) JTSAdapter.wrap(p);

            final java.awt.Point awt = MapUtilities.retransform(mapPanel, gmp);
            x = ArrayUtils.add(x, awt.x);
            y = ArrayUtils.add(y, awt.y);
        } catch (final GM_Exception e) {
            KalypsoCorePlugin.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e));
        }
    }

    Assert.isTrue(x.length == y.length);

    final java.awt.Polygon poly = new java.awt.Polygon(x, y, x.length);

    final Color original = g.getColor();

    g.setColor(fill);
    g.fillPolygon(poly);

    g.setColor(border);
    g.drawPolygon(poly);

    g.setColor(original);

}

From source file:CheckBoxSample.java

public void paintIcon(Component component, Graphics g, int x, int y) {
    boolean selected = false;
    g.setColor(color);
    g.translate(x, y);// w  ww.  j av  a  2 s  .  c om
    if (component instanceof AbstractButton) {
        AbstractButton abstractButton = (AbstractButton) component;
        selected = abstractButton.isSelected();
    }
    if (selected) {
        g.fillPolygon(polygon);
    } else {
        g.drawPolygon(polygon);
    }
    g.translate(-x, -y);
}

From source file:painting.SwingPaintDemo3.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!", 10, 20);
    g.setColor(Color.RED);
    g.fillRect(squareX, squareY, squareW, squareH);
    g.setColor(Color.BLACK);//  w ww . ja  v  a2  s .co  m
    g.drawRect(squareX, squareY, squareW, squareH);
}

From source file:Main.java

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

    Ellipse2D e = new Ellipse2D.Float(w / 4.0f, h / 4.0f, w / 2.0f, h / 2.0f);
    g.setClip(e);//  ww w . j  a  va2  s.  co m

    g.setColor(Color.red);
    g.fillRect(0, 0, w, h);

}

From source file:Main.java

@Override
public void paintComponent(Graphics gr) {
    Color c = gr.getColor();/*from ww w . ja v  a2 s.  c om*/
    setForeground(new Color(0, 0, 0, 0));
    super.paintComponent(gr);
    setForeground(c);
    gr.setColor(c);
    Graphics2D g = (Graphics2D) gr;
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    double pw = this.getPreferredSize().width;
    double ph = this.getPreferredSize().height;
    double w = this.getSize().width;
    double h = this.getSize().height;

    g.setColor(this.getForeground());

    AffineTransform stretch = AffineTransform.getScaleInstance(w / pw, h / ph);
    g.setTransform(stretch);
    g.drawString(getText(), 0, this.getFont().getSize());
}

From source file:ImageTransferTest.java

public ImageTransferFrame() {
    setTitle("ImageTransferTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    label = new JLabel();
    image = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    g.setColor(Color.RED);/* w  w  w .  j av a  2 s.c  o m*/
    g.fillOval(DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 4, DEFAULT_WIDTH / 2, DEFAULT_HEIGHT / 2);

    label.setIcon(new ImageIcon(image));
    add(new JScrollPane(label), BorderLayout.CENTER);
    JPanel panel = new JPanel();

    JButton copyButton = new JButton("Copy");
    panel.add(copyButton);
    copyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            copy();
        }
    });

    JButton pasteButton = new JButton("Paste");
    panel.add(pasteButton);
    pasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            paste();
        }
    });

    add(panel, BorderLayout.SOUTH);
}