java.awt.Graphics.fillRect()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(2218)

本文整理了Java中java.awt.Graphics.fillRect()方法的一些代码示例,展示了Graphics.fillRect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graphics.fillRect()方法的具体详情如下:
包路径:java.awt.Graphics
类名称:Graphics
方法名:fillRect

Graphics.fillRect介绍

[英]Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.
[中]填充指定的矩形。矩形的左边缘和右边缘分别位于xx + width - 1。顶部和底部边缘分别位于yy + height - 1。结果矩形覆盖的区域宽width像素,高height像素。使用图形上下文的当前颜色填充矩形。

代码示例

代码示例来源:origin: libgdx/libgdx

static Icon getColorIcon (java.awt.Color color) {
  BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB);
  java.awt.Graphics g = image.getGraphics();
  g.setColor(color);
  g.fillRect(1, 1, 30, 14);
  g.setColor(java.awt.Color.black);
  g.drawRect(0, 0, 31, 15);
  return new ImageIcon(image);
}

代码示例来源:origin: stackoverflow.com

+ "The effect we want is a multi-line label.";
JFrame f = new JFrame("Label Render Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  Color.orange);
imageGraphics.setPaint(gp);
imageGraphics.fillRect(0, 0, 400, 300);
  BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
g.setColor(new Color(255, 255, 255, 128));
g.fillRoundRect(
  0,
  15,
  10);
g.setColor(Color.black);
textLabel.paint(g);
Graphics g2 = image.getGraphics();
JLabel imageLabel = new JLabel(ii);
f.getContentPane().add(imageLabel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

constraints.fill = GridBagConstraints.BOTH;
JLabel l = new JLabel("You have got 2 new Messages.");
panel.add(l, constraints);
constraints.gridx++;
constraints.weightx = 0f;
b.setMargin(new Insets(1, 4, 1, 4));
b.setFocusable(false);
panel.add(b, constraints);
dialog.setUndecorated(true);
dialog.setSize(300, 100);
  final Graphics2D g2d = (Graphics2D) g;
  g2d.setPaint(lpg);
  g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
  g2d.setColor(Color.BLACK);
  g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
  frame.add(new JPanel(){
   @Override
   public void paintComponent(Graphics g) {
     super.paintComponent(g);
     g.setColor(Color.YELLOW);
     g.fillRect(50, 50, 100, 100);
   }
  });

代码示例来源:origin: stackoverflow.com

super.paintComponent(g);
if (this.isLiving) {
  g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
} else {
  g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
    GameOfLife cell = new GameOfLife(ii, jj);
    cell.setPreferredSize(new Dimension(10, 10));
    gui.add(cell);
    biosphere[ii][jj] = cell;

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.*;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.setSize(600, 400);

    JPanel panel = new JPanel() {
      @Override
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, 100, 100);
      }
    };
    frame.add(panel);

    // Graphics g = panel.getGraphics();
    // g.setColor(Color.BLUE);
    // g.fillRect(0, 0, 100, 100);

    frame.validate(); // because you added panel after setVisible was called
    frame.repaint(); // because you added panel after setVisible was called
  }
}

代码示例来源:origin: libgdx/libgdx

static Icon getColorIcon (java.awt.Color color) {
  BufferedImage image = new BufferedImage(32, 16, BufferedImage.TYPE_INT_RGB);
  java.awt.Graphics g = image.getGraphics();
  g.setColor(color);
  g.fillRect(1, 1, 30, 14);
  g.setColor(java.awt.Color.black);
  g.drawRect(0, 0, 31, 15);
  return new ImageIcon(image);
}

代码示例来源:origin: stackoverflow.com

gui.add(l1);
    l2.setBackground(Color.YELLOW);
    l2.setOpaque(true);
    gui.add(l2);
    p1.add(new JLabel("Panel 1"));
    p1.setBorder(brdrRight);
    p1.setOpaque(false);
  borderRegion.subtract(area);
  g2.setClip(borderRegion);
  g2.setColor(bg);
  g2.fillRect(0, 0, width, height);
  g2.setClip(null);
g2.setColor(color);
g2.setStroke(stroke);
g2.draw(area);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
 JComponent canvas = new JComponent() {
   protected void paintComponent(Graphics g) {
     //call repaint(g) here instead of this
     g.setColor(Color.RED);
     g.fillRect(0, 0, getWidth(), getHeight());
   };
 };
 frame.add(canvas);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
  frame.setSize(600, 400);
  frame.add(panel);
public void paintComponent(Graphics g) {
  super.paintComponent(g);
  g.setColor(Color.BLUE);
  g.fillRect(0, 0, 100, 100);

代码示例来源:origin: runelite/runelite

/**
 * Overrides the painting of the bar's track (the darker part underneath that extends
 * the full page length).
 */
@Override
protected void paintTrack(Graphics graphics, JComponent jComponent, Rectangle rectangle)
{
  graphics.setColor(trackColor);
  graphics.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
}

代码示例来源:origin: stackoverflow.com

g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
g2d.setColor(Color.BLACK);
 l.setOpaque(false);
 c.add(l, constraints);
 b.setFocusable(false);
 c.add(b, constraints);

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) {
  FrameTestBase t = new FrameTestBase();
  t.add(new JComponent() {
    public void paintComponent(Graphics g) {
      String str = "hello world!";
      Rectangle2D rect = fm.getStringBounds(str, g);
      g.setColor(bgColor);
      g.fillRect(x,
            y - fm.getAscent(),
            (int) rect.getWidth(),
            (int) rect.getHeight());
      g.setColor(textColor);
      g.drawString(str, x, y);
  t.setDefaultCloseOperation(EXIT_ON_CLOSE);
  t.setSize(400, 200);
  t.setVisible(true);

代码示例来源:origin: runelite/runelite

/**
 * Overrides the painting of the bar's thumb (the lighter part on top that users
 * use to slide up and down the page).
 */
@Override
protected void paintThumb(Graphics graphics, JComponent jComponent, Rectangle rectangle)
{
  graphics.setColor(thumbColor);
  graphics.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
}

代码示例来源:origin: stackoverflow.com

gui.add(quality, BorderLayout.WEST);
dithering = new JCheckBox("Dithering", false);
controls.add(antialiasing);
controls.add(fractionalMetrics);
  (float)width, (float)height, Color.orange);
g2d.setPaint(gp);
g2d.fillRect(0,0, width, height);
g2d.setColor(Color.blue);
for (int ii=0; ii<width; ii+=10) {
  g2d.drawLine(ii, 0, ii, height);
g2d.setColor(Color.green);
for (int jj=0; jj<height; jj+=10) {
  g2d.drawLine(0, jj, width, jj);
g2dText.setColor(Color.black);
g2dText.drawString("The quick brown fox jumped over the lazy dog.", 10,50);

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
  20f,20f,Color.red, 180f,180f,Color.yellow);
g.setPaint(gp);
g.fillRect(0,0,200,200);
ImageIcon ii = new ImageIcon(bi);
JLabel imageLabel = new JLabel(ii);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

@Override
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  int width = this.getWidth();
  int height = this.getHeight();
  g.setColor(Color.black);
  g.fillRect(0, 0, width, height);
  ...
}

代码示例来源:origin: stackoverflow.com

g2.setColor(Color.WHITE);
g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding);
g2.setColor(Color.BLACK);
  int y1 = y0;
  if (scores.size() > 0) {
    g2.setColor(gridColor);
    g2.drawLine(padding + labelPadding + 1 + pointWidth, y0, getWidth() - padding, y1);
    g2.setColor(Color.BLACK);
JFrame frame = new JFrame("DrawGraph");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

int width = 200;
int height = 400;
BufferedImage image = new BufferedImage(width, height,
             BufferedImage.TYPE_BYTE_BINARY);
Graphics g = image.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.setColor(Color.BLACK);
//ready for drawing

代码示例来源:origin: stackoverflow.com

int cellX = 10 + (fillCell.x * 10);
  int cellY = 10 + (fillCell.y * 10);
  g.setColor(Color.RED);
  g.fillRect(cellX, cellY, 10, 10);
g.setColor(Color.BLACK);
g.drawRect(10, 10, 800, 500);
  JFrame window = new JFrame();
  window.setSize(840, 560);
  window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  window.add(grid);
  window.setVisible(true);
  grid.fillCell(0, 0);
  grid.fillCell(79, 0);

相关文章