List of usage examples for java.awt Graphics fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:TrackFocusDemo.java
protected void paintComponent(Graphics graphics) { Graphics g = graphics.create(); //Draw in our entire space, even if isOpaque is false. g.setColor(Color.WHITE);/*from w w w. j a v a 2 s . co m*/ g.fillRect(0, 0, image == null ? 125 : image.getWidth(this), image == null ? 125 : image.getHeight(this)); if (image != null) { //Draw image at its natural size of 125x125. g.drawImage(image, 0, 0, this); } //Add a border, red if picture currently has focus if (isFocusOwner()) { g.setColor(Color.RED); } else { g.setColor(Color.BLACK); } g.drawRect(0, 0, image == null ? 125 : image.getWidth(this), image == null ? 125 : image.getHeight(this)); g.dispose(); }
From source file:SWTTest.java
/** * Prepare the AWT offscreen image for the rendering of the rectangular * region given as parameter./*w w w .j av a 2 s .c o m*/ */ private void prepareRendering(int clipX, int clipY, int clipW, int clipH) { // check that the offscreen images are initialized and large enough checkOffScreenImages(clipW, clipH); // fill the region in the AWT image with the transparent color java.awt.Graphics awtGraphics = awtImage.getGraphics(); awtGraphics.setColor(new java.awt.Color(TRANSPARENT_COLOR)); awtGraphics.fillRect(clipX, clipY, clipW, clipH); }
From source file:Main.java
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { return new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Font font = (Font) value; String text = font.getFamily(); FontMetrics fm = g.getFontMetrics(font); g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground()); g.setFont(font);//from w w w.j a v a2s . c o m g.drawString(text, 0, fm.getAscent()); } public Dimension getPreferredSize() { Font font = (Font) value; String text = font.getFamily(); Graphics g = getGraphics(); FontMetrics fm = g.getFontMetrics(font); return new Dimension(fm.stringWidth(text), fm.getHeight()); } }; }
From source file:components.Rule.java
protected void paintComponent(Graphics g) { Rectangle drawHere = g.getClipBounds(); // Fill clipping area with dirty brown/orange. g.setColor(new Color(230, 163, 4)); g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height); // Do the ruler labels in a small font that's black. g.setFont(new Font("SansSerif", Font.PLAIN, 10)); g.setColor(Color.black);//www . j a v a 2s .co m // Some vars we need. int end = 0; int start = 0; int tickLength = 0; String text = null; // Use clipping bounds to calculate first and last tick locations. if (orientation == HORIZONTAL) { start = (drawHere.x / increment) * increment; end = (((drawHere.x + drawHere.width) / increment) + 1) * increment; } else { start = (drawHere.y / increment) * increment; end = (((drawHere.y + drawHere.height) / increment) + 1) * increment; } // Make a special case of 0 to display the number // within the rule and draw a units label. if (start == 0) { text = Integer.toString(0) + (isMetric ? " cm" : " in"); tickLength = 10; if (orientation == HORIZONTAL) { g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1); g.drawString(text, 2, 21); } else { g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0); g.drawString(text, 9, 10); } text = null; start = increment; } // ticks and labels for (int i = start; i < end; i += increment) { if (i % units == 0) { tickLength = 10; text = Integer.toString(i / units); } else { tickLength = 7; text = null; } if (tickLength != 0) { if (orientation == HORIZONTAL) { g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1); if (text != null) g.drawString(text, i - 3, 21); } else { g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i); if (text != null) g.drawString(text, 9, i + 3); } } } }
From source file:Main.java
private void drawPass(Graphics g) { int rectWidth = 1; int width = getWidth() - 1; int height = getHeight() - 1; int colSpan = Math.round((float) width / (float) numbers.length); int x = 0;//w w w . j ava 2s . c o m for (int num : numbers) { int colHeight = (int) ((float) height * ((float) num / (float) 100)); g.fillRect(x, height - colHeight, rectWidth, colHeight); x += colSpan; } }
From source file:se.llbit.chunky.map.BlockLayer.java
/** * Render block highlight/*from ww w .j av a 2 s . c o m*/ * @param rbuff * @param cx * @param cz * @param hlBlock * @param highlight */ @Override public synchronized void renderHighlight(MapBuffer rbuff, int cx, int cz, Block hlBlock, java.awt.Color highlight) { ChunkView view = rbuff.getView(); int x0 = view.chunkScale * (cx - view.px0); int z0 = view.chunkScale * (cz - view.pz0); if (blocks == null) return; Graphics g = rbuff.getGraphics(); g.setColor(new java.awt.Color(1, 1, 1, 0.35f)); g.fillRect(x0, z0, view.chunkScale, view.chunkScale); g.setColor(highlight); if (view.chunkScale == 16) { for (int x = 0; x < 16; ++x) { int xp = x0 + x; for (int z = 0; z < 16; ++z) { int yp = z0 + z; if (hlBlock.id == (0xFF & blocks[x * 16 + z])) { rbuff.setRGB(xp, yp, highlight.getRGB()); } } } } else { int blockScale = view.chunkScale / 16; for (int x = 0; x < 16; ++x) { int xp0 = x0 + x * blockScale; int xp1 = xp0 + blockScale; for (int z = 0; z < 16; ++z) { int yp0 = z0 + z * blockScale; int yp1 = yp0 + blockScale; if (hlBlock.id == (0xFF & blocks[x * 16 + z])) { g.fillRect(xp0, yp0, xp1 - xp0, yp1 - yp0); } } } } }
From source file:ScaleTest_2008.java
/** * Paints the test image that will be downscaled and timed by the various * scaling methods. A different image is rendered into each of the four * quadrants of this image: RGB stripes, a picture, vector art, and * a black and white grid.//from w w w . jav a 2 s. co m */ private void paintOriginalImage() { Graphics g = originalImage.getGraphics(); // Erase to black g.setColor(Color.BLACK); g.fillRect(0, 0, FULL_SIZE, FULL_SIZE); // RGB quadrant for (int i = 0; i < QUAD_SIZE; i += 3) { int x = i; g.setColor(Color.RED); g.drawLine(x, 0, x, QUAD_SIZE); x++; g.setColor(Color.GREEN); g.drawLine(x, 0, x, QUAD_SIZE); x++; g.setColor(Color.BLUE); g.drawLine(x, 0, x, QUAD_SIZE); } // Picture quadrant try { URL url = getClass().getResource("BBGrayscale.png"); BufferedImage picture = ImageIO.read(url); // Center picture in quadrant area int xDiff = QUAD_SIZE - picture.getWidth(); int yDiff = QUAD_SIZE - picture.getHeight(); g.drawImage(picture, QUAD_SIZE + xDiff / 2, yDiff / 2, null); } catch (Exception e) { System.out.println("Problem reading image file: " + e); } // Vector drawing quadrant g.setColor(Color.WHITE); g.fillRect(0, QUAD_SIZE, QUAD_SIZE, QUAD_SIZE); g.setColor(Color.BLACK); g.drawOval(2, QUAD_SIZE + 2, QUAD_SIZE - 4, QUAD_SIZE - 4); g.drawArc(20, QUAD_SIZE + 20, (QUAD_SIZE - 40), QUAD_SIZE - 40, 190, 160); int eyeSize = 7; int eyePos = 30 - (eyeSize / 2); g.fillOval(eyePos, QUAD_SIZE + eyePos, eyeSize, eyeSize); g.fillOval(QUAD_SIZE - eyePos - eyeSize, QUAD_SIZE + eyePos, eyeSize, eyeSize); // B&W grid g.setColor(Color.WHITE); g.fillRect(QUAD_SIZE + 1, QUAD_SIZE + 1, QUAD_SIZE, QUAD_SIZE); g.setColor(Color.BLACK); for (int i = 0; i < QUAD_SIZE; i += 4) { int pos = QUAD_SIZE + i; g.drawLine(pos, QUAD_SIZE + 1, pos, FULL_SIZE); g.drawLine(QUAD_SIZE + 1, pos, FULL_SIZE, pos); } originalImagePainted = true; }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.WHITE);/*from ww w .ja v a2 s . c o m*/ int size = myModel.arraySize; int barWidth = getWidth() / size; for (int i = 0; i < size; i++) { int value = myModel.myArray[i]; int x = i * barWidth; int y = getHeight() - value; g.fillRect(x + 1, y, barWidth - 2, value); } }
From source file:ColorIcon.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(border);/*from w ww .ja v a 2 s . co m*/ g.drawRect(x, y, iWidth - 1, iHeight - 2); x += insets.left; y += insets.top; int w = iWidth - insets.left - insets.right; int h = iHeight - insets.top - insets.bottom - 1; g.setColor(color); g.fillRect(x, y, w, h); }
From source file:org.mili.core.graphics.GraphicsUtilTest.java
@Before public void setUp() throws Exception { FileUtils.deleteDirectory(this.dir); this.dir.mkdirs(); // original image BufferedImage outImg = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics g = outImg.getGraphics(); g.setColor(Color.YELLOW);//from ww w. j a va2 s.c o m g.fillRect(0, 0, 50, 50); g.dispose(); ImageIO.write(outImg, "jpeg", new File(this.dir, "test.jpg")); // original image 2 outImg = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); g = outImg.getGraphics(); g.setColor(Color.YELLOW); g.fillRect(0, 0, 200, 200); g.dispose(); ImageIO.write(outImg, "jpeg", new File(this.dir, "test_big.jpg")); // image to set outImg = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB); g = outImg.getGraphics(); g.setColor(Color.BLUE); g.fillRect(0, 0, 20, 20); g.dispose(); ImageIO.write(outImg, "jpeg", new File(this.dir, "block.jpg")); }