Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

In this page you can find the example usage for java.awt Graphics 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
public void paintComponent(Graphics g) {
    g.setColor(Color.getHSBColor(new Random().nextFloat(), 1, 1));
    g.fillRect(0, 0, getWidth(), getHeight());
}

From source file:mainDraw.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawRect(x, y, 50, 50);//  w  ww. j  a  v a  2 s  . c om
    g.fillRect(x, y, 50, 50);
    g.setColor(Color.BLACK);
}

From source file:LineHighlightPainter.java

private void paintLine(Graphics g, Rectangle r, int x2) {
    int ytop = r.y + r.height - 3;
    g.fillRect(r.x, ytop, x2 - r.x, 3);
}

From source file:Main.java

public Main() {
    this.setLayout(new FlowLayout());
    this.add(new JButton("test"));
    this.add(new JCheckBox("test"));
    this.add(new JRadioButton("test"));
    this.add(new JProgressBar(0, 100));
    JPanel panel = new JPanel() {
        @Override/* w ww  .j av  a  2 s. c  o  m*/
        public Dimension getPreferredSize() {
            return new Dimension(400, 300);
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.red);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    panel.add(new JLabel("Label"));
    add(panel);
    setSize(new Dimension(400, 300));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:MainClass.java

public void paint(Graphics g) {
    int deltax = 260 / colors.length;
    for (int i = 0; i < colors.length; i++) {
        g.setColor(colors[i]);//  w  ww  . ja  v  a 2 s  .co m
        g.fillRect(i * deltax, 0, (i + 1) * deltax, 260);
    }

}

From source file:PlainColorIcon.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    Color old_color = g.getColor();
    g.setColor(color);/*from  w w w  .j a  va2  s  .  c  o  m*/
    g.fillRect(x, y, 10, 10);
    g.setColor(old_color);
}

From source file:SaveYourDrawingToFile.java

public void paint(Graphics g) {
    g.setColor(Color.white);//w ww .  j  av a  2  s. c o  m
    g.fillRect(0, 0, getSize().width, getSize().height);

    g.setColor(Color.black);
    int i = 0;
    while (i < displayList.size()) {
        Point p0 = (Point) (displayList.get(i++));
        Point p1 = (Point) (displayList.get(i++));
        int x = Math.min(p0.x, p1.x);
        int y = Math.min(p0.y, p1.y);
        int w = Math.abs(p0.x - p1.x);
        int h = Math.abs(p0.y - p1.y);
        g.drawRect(x, y, w, h);
    }
}

From source file:BufferedAnimate.java

public void paint(Graphics g) {
    if ((oldSize == null) || (oldSize != getSize())) {
        oldSize = getSize();/*from   www  .  j a  va2 s.co m*/
        buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    }
    if (insets == null) {
        insets = getInsets();
    }
    // Calculate each time in case of resize
    int x = insets.left;
    int y = insets.top;
    int width = getWidth() - insets.left - insets.right;
    int height = getHeight() - insets.top - insets.bottom;
    int start = 0;
    int steps = colors.length;
    int stepSize = 360 / steps;
    synchronized (colors) {
        Graphics bufferG = buffer.getGraphics();
        bufferG.setColor(Color.WHITE);
        bufferG.fillRect(x, y, width, height);
        for (int i = 0; i < steps; i++) {
            bufferG.setColor(colors[i]);
            bufferG.fillArc(x, y, width, height, start, stepSize);
            start += stepSize;
        }
    }
    g.drawImage(buffer, 0, 0, this);
}

From source file:QandE.StripeBorder.java

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

    g.fillRect(x, y, c.getWidth(), HEIGHT);
}

From source file:DialogSeparator.java

public void paint(Graphics g) {
    g.setColor(getBackground());//from w  w w.  j  av  a 2  s.  c o  m
    g.fillRect(0, 0, getWidth(), getHeight());

    Dimension d = getSize();
    int y = (d.height - 3) / 2;
    g.setColor(Color.white);
    g.drawLine(1, y, d.width - 1, y);
    y++;
    g.drawLine(0, y, 1, y);
    g.setColor(Color.gray);
    g.drawLine(d.width - 1, y, d.width, y);
    y++;
    g.drawLine(1, y, d.width - 1, y);

    String text = getText();
    if (text.length() == 0)
        return;

    g.setFont(getFont());
    FontMetrics fm = g.getFontMetrics();
    y = (d.height + fm.getAscent()) / 2;
    int fontWidth = fm.stringWidth(text);

    g.setColor(getBackground());
    g.fillRect(OFFSET - 5, 0, OFFSET + fontWidth, d.height);

    g.setColor(getForeground());
    g.drawString(text, OFFSET, y);
}