Tabnine Logo
Graphics.fillRect
Code IndexAdd Tabnine to your IDE (free)

How to use
fillRect
method
in
java.awt.Graphics

Best Java code snippets using java.awt.Graphics.fillRect (Showing top 20 results out of 4,689)

Refine searchRefine arrow

  • Graphics.setColor
  • Window.setVisible
  • Container.add
  • JFrame.setDefaultCloseOperation
  • JFrame.<init>
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);
java.awtGraphicsfillRect

Javadoc

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.

Popular methods of Graphics

  • setColor
  • drawImage
    Draws as much of the specified image as is currently available. The image is drawn with its top-left
  • drawLine
    Draws a line, using the current color, between the points(x1, y1) and (x2, y2) in this graphics con
  • drawString
    Draws the text given by the specified iterator, using this graphics context's current color. The ite
  • dispose
    Disposes of this graphics context and releases any system resources that it is using. A Graphics obj
  • setFont
    Sets this graphics context's font to the specified font. All subsequent text operations using this g
  • drawRect
    Draws the outline of the specified rectangle. The left and right edges of the rectangle are atx and
  • getFontMetrics
  • create
    Creates a new Graphics object based on thisGraphics object, but with a new translation and clip area
  • getColor
    Gets this graphics context's current color.
  • translate
    Translates the origin of the graphics context to the point (x,y) in the current coordinate system. M
  • getClipBounds
    Returns the bounding rectangle of the current clipping area. The coordinates in the rectangle are re
  • translate,
  • getClipBounds,
  • setClip,
  • getFont,
  • fillPolygon,
  • fillOval,
  • drawOval,
  • getClip,
  • drawRoundRect

Popular in Java

  • Reactive rest calls using spring rest template
  • putExtra (Intent)
  • startActivity (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now