Java Code Examples for java.awt.Graphics#setColor()
The following examples show how to use
java.awt.Graphics#setColor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MotifGraphicsUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void drawMenuBezel(Graphics g, Color background, int x, int y, int width, int height) { // shadowed button region g.setColor(background); g.fillRect(x,y,width,height); g.setColor(background.brighter().brighter()); g.drawLine(x+1, y+height-1, x+width-1, y+height-1); g.drawLine(x+width-1, y+height-2, x+width-1, y+1); g.setColor(background.darker().darker()); g.drawLine(x, y, x+width-2, y); g.drawLine(x, y+1, x, y+height-2); }
Example 2
Source File: MotifGraphicsUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight) { Color oldColor = g.getColor(); // Make no net change to g g.translate(x, y); g.setColor(shadow); g.drawRect(0, 0, w-2, h-2); g.setColor(highlight); g.drawLine(1, h-3, 1, 1); g.drawLine(1, 1, w-3, 1); g.drawLine(0, h-1, w-1, h-1); g.drawLine(w-1, h-1, w-1, 0); g.translate(-x, -y); g.setColor(oldColor); }
Example 3
Source File: CheckRenderer.java From Spark with Apache License 2.0 | 6 votes |
@Override public void paint(Graphics g) { String str; if ((str = getText()) != null) { if (0 < str.length()) { if (isSelected) { g.setColor(UIManager.getColor("Tree.selectionBackground")); } else { g.setColor(UIManager.getColor("Tree.textBackground")); } Dimension d = getPreferredSize(); int imageOffset = 0; Icon currentI = getIcon(); if (currentI != null) { imageOffset = currentI.getIconWidth() + Math.max(0, getIconTextGap() - 1); } g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, d.height); if (hasFocus) { g.setColor(UIManager.getColor("Tree.selectionBorderColor")); g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, d.height - 1); } } } super.paint(g); }
Example 4
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
protected void paintComponent(Graphics g) { if (!pattern || component == null) { super.paintComponent(g); } else { int x = 0; int y = 0; int w = getWidth(); int h = getHeight(); while (y <= h) { boolean flag = (y / DASH_SIZE) % 2 == 0; while (x <= w) { g.setColor(flag ? getBackground() : getForeground()); g.fillRect(x, y, DASH_SIZE, DASH_SIZE); x += DASH_SIZE; flag = !flag; } x = 0; y += DASH_SIZE; } } }
Example 5
Source File: SharedMemoryPixmapsTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void initVI() { int res; if (vi == null) { res = VolatileImage.IMAGE_INCOMPATIBLE; } else { res = vi.validate(getGraphicsConfiguration()); } if (res == VolatileImage.IMAGE_INCOMPATIBLE) { if (vi != null) vi.flush(); vi = createVolatileImage(IMAGE_SIZE, IMAGE_SIZE); vi.validate(getGraphicsConfiguration()); res = VolatileImage.IMAGE_RESTORED; } if (res == VolatileImage.IMAGE_RESTORED) { Graphics vig = vi.getGraphics(); vig.setColor(Color.red); vig.fillRect(0, 0, vi.getWidth(), vi.getHeight()); vig.dispose(); } }
Example 6
Source File: BasicSeparatorUI.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void paint( Graphics g, JComponent c ) { Dimension s = c.getSize(); if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL ) { g.setColor( c.getForeground() ); g.drawLine( 0, 0, 0, s.height ); g.setColor( c.getBackground() ); g.drawLine( 1, 0, 1, s.height ); } else // HORIZONTAL { g.setColor( c.getForeground() ); g.drawLine( 0, 0, s.width, 0 ); g.setColor( c.getBackground() ); g.drawLine( 0, 1, s.width, 1 ); } }
Example 7
Source File: RenderTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { RenderTests.Context rctx = (RenderTests.Context) ctx; int size = rctx.size; int x = rctx.initX; int y = rctx.initY; Graphics g = rctx.graphics; g.translate(rctx.orgX, rctx.orgY); Color rCArray[] = rctx.colorlist; int ci = rctx.colorindex; if (rctx.animate) { do { if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.fillRect(x, y, size, size); if ((x -= 3) < 0) x += rctx.maxX; if ((y -= 1) < 0) y += rctx.maxY; } while (--numReps > 0); } else { do { if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.fillRect(x, y, size, size); } while (--numReps > 0); } rctx.colorindex = ci; g.translate(-rctx.orgX, -rctx.orgY); }
Example 8
Source File: PortalAnimation.java From IngressAnimations with GNU General Public License v3.0 | 5 votes |
@Override public void draw(Graphics gr, ScaleAnimation scale, double t) { double portalTop = py+12; double portalBot = py-12; double portalLeft = px-12; double portalRigt = px+12; if (! (scale instanceof AxisAlignedScale)) { throw new UnsupportedOperationException("portal circle calculations are not supported for scale "+scale.getClass()); } int[] topLeft = scale.getScale(t).toGraphics(portalLeft, portalTop); int[] botRigt = scale.getScale(t).toGraphics(portalRigt, portalBot); int height = botRigt[1] - topLeft[1]; int width = botRigt[0] - topLeft[0]; Color c = getColor(t); gr.setColor(c.darker()); gr.fillOval(topLeft[0], topLeft[1], width, height); gr.setColor(c); ((Graphics2D) gr).setStroke(new BasicStroke(width/6f)); gr.drawOval(topLeft[0], topLeft[1], width, height); Label label = getLabel(t); if (label == null) { return; } gr.setFont(gr.getFont().deriveFont(height*1.5f)); label.draw(gr, topLeft, botRigt, c); }
Example 9
Source File: XComponentPeer.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void draw3DRect(Graphics g, Color colors[], int x, int y, int width, int height, boolean raised) { Color c = g.getColor(); g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); g.drawLine(x, y, x, y + height); g.drawLine(x + 1, y, x + width - 1, y); g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); g.drawLine(x + 1, y + height, x + width, y + height); g.drawLine(x + width, y, x + width, y + height - 1); g.setColor(c); }
Example 10
Source File: AltTabCrashTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public SpriteBall(int x, int y) { super(x, y); image = createSprite(); Graphics g = image.getGraphics(); g.setColor(color); g.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); }
Example 11
Source File: ColorChooserButton.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private static ImageIcon makeColorIconForColor(final Color color) { final Image img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); final Graphics gfx = img.getGraphics(); try { if (color == null) { gfx.setColor(NbUtils.DARK_THEME ? Color.darkGray : Color.white); gfx.fillRect(0, 0, 16, 16); gfx.setColor(NbUtils.DARK_THEME ? Color.yellow : Color.black); gfx.drawRect(0, 0, 15, 15); gfx.drawLine(0, 0, 15, 15); } else if (color == DIFF_COLORS) { gfx.setColor(Color.red); gfx.fillRect(0, 0, 8, 8); gfx.setColor(Color.green); gfx.fillRect(8, 0, 8, 8); gfx.setColor(Color.blue); gfx.fillRect(0, 8, 8, 8); gfx.setColor(Color.yellow); gfx.fillRect(8, 8, 8, 8); } else { gfx.setColor(color); gfx.fillRect(0, 0, 16, 16); gfx.setColor(Color.black); gfx.drawRect(0, 0, 15, 15); } } finally { gfx.dispose(); } return new ImageIcon(img); }
Example 12
Source File: HintTextFieldUI.java From azure-devops-intellij with MIT License | 5 votes |
@Override protected void paintSafely(Graphics g) { super.paintSafely(g); JTextComponent component = getComponent(); if (hintText != null && component.getText().length() == 0 && !component.hasFocus()) { g.setColor(JBColor.GRAY); final int fontSize = component.getFont().getSize(); final int padding = (component.getHeight() - fontSize) / 2; final int x = component.getInsets().left; final int y = component.getHeight() - padding - 1; g.drawString(hintText, x, y); } }
Example 13
Source File: BasicLabelUI.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Paint clippedText at textX, textY with background.lighter() and then * shifted down and to the right by one pixel with background.darker(). * * @see #paint * @see #paintEnabledText */ protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { int accChar = l.getDisplayedMnemonicIndex(); Color background = l.getBackground(); g.setColor(background.brighter()); SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar, textX + 1, textY + 1); g.setColor(background.darker()); SwingUtilities2.drawStringUnderlineCharAt(l, g, s, accChar, textX, textY); }
Example 14
Source File: Block.java From javagame with MIT License | 5 votes |
/** * �u���b�N�̕`�� * * @param g �`��I�u�W�F�N�g */ public void draw(Graphics g) { g.setColor(Color.MAGENTA); for (int i = 0; i < ROW; i++) { for (int j = 0; j < COL; j++) { if (block[i][j] == 1) { // pos�̈ʒu����Ƃ���_�ɒ��ӁI g.fillRect((pos.x + j) * TILE_SIZE, (pos.y + i) * TILE_SIZE, TILE_SIZE, TILE_SIZE); } } } }
Example 15
Source File: SwingOnScreenScrollingTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected void paintComponent(Graphics g) { g.setColor(Color.green); g.fillRect(0, 0, getWidth(), 100); g.setColor(Color.red); g.fillRect(0, 100, getWidth(), getHeight()-100); }
Example 16
Source File: BasicGraphicsUtils.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void drawBezel(Graphics g, int x, int y, int w, int h, boolean isPressed, boolean isDefault, Color shadow, Color darkShadow, Color highlight, Color lightHighlight) { Color oldColor = g.getColor(); // Make no net change to g g.translate(x, y); if (isPressed && isDefault) { g.setColor(darkShadow); g.drawRect(0, 0, w - 1, h - 1); g.setColor(shadow); g.drawRect(1, 1, w - 3, h - 3); } else if (isPressed) { drawLoweredBezel(g, x, y, w, h, shadow, darkShadow, highlight, lightHighlight); } else if (isDefault) { g.setColor(darkShadow); g.drawRect(0, 0, w-1, h-1); g.setColor(lightHighlight); g.drawLine(1, 1, 1, h-3); g.drawLine(2, 1, w-3, 1); g.setColor(highlight); g.drawLine(2, 2, 2, h-4); g.drawLine(3, 2, w-4, 2); g.setColor(shadow); g.drawLine(2, h-3, w-3, h-3); g.drawLine(w-3, 2, w-3, h-4); g.setColor(darkShadow); g.drawLine(1, h-2, w-2, h-2); g.drawLine(w-2, h-2, w-2, 1); } else { g.setColor(lightHighlight); g.drawLine(0, 0, 0, h-1); g.drawLine(1, 0, w-2, 0); g.setColor(highlight); g.drawLine(1, 1, 1, h-3); g.drawLine(2, 1, w-3, 1); g.setColor(shadow); g.drawLine(1, h-2, w-2, h-2); g.drawLine(w-2, 1, w-2, h-3); g.setColor(darkShadow); g.drawLine(0, h-1, w-1, h-1); g.drawLine(w-1, h-1, w-1, 0); } g.translate(-x, -y); g.setColor(oldColor); }
Example 17
Source File: MotifIconFactory.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); // These variables are kind of pointless as the following code // assumes the icon will be 10 x 10 regardless of their value. int w = getIconWidth(); int h = getIconHeight(); Color oldColor = g.getColor(); if (model.isSelected()){ if( MotifGraphicsUtils.isLeftToRight(c) ){ g.setColor(shadow); g.fillRect(x+1,y+1,2,h); g.drawLine(x+4,y+2,x+4,y+2); g.drawLine(x+6,y+3,x+6,y+3); g.drawLine(x+8,y+4,x+8,y+5); g.setColor(focus); g.fillRect(x+2,y+2,2,h-2); g.fillRect(x+4,y+3,2,h-4); g.fillRect(x+6,y+4,2,h-6); g.setColor(highlight); g.drawLine(x+2,y+h,x+2,y+h); g.drawLine(x+4,y+h-1,x+4,y+h-1); g.drawLine(x+6,y+h-2,x+6,y+h-2); g.drawLine(x+8,y+h-4,x+8,y+h-3); } else { g.setColor(highlight); g.fillRect(x+7,y+1,2,10); g.drawLine(x+5,y+9,x+5,y+9); g.drawLine(x+3,y+8,x+3,y+8); g.drawLine(x+1,y+6,x+1,y+7); g.setColor(focus); g.fillRect(x+6,y+2,2,8); g.fillRect(x+4,y+3,2,6); g.fillRect(x+2,y+4,2,4); g.setColor(shadow); g.drawLine(x+1,y+4,x+1,y+5); g.drawLine(x+3,y+3,x+3,y+3); g.drawLine(x+5,y+2,x+5,y+2); g.drawLine(x+7,y+1,x+7,y+1); } } else { if( MotifGraphicsUtils.isLeftToRight(c) ){ g.setColor(highlight); g.drawLine(x+1,y+1,x+1,y+h); g.drawLine(x+2,y+1,x+2,y+h-2); g.fillRect(x+3,y+2,2,2); g.fillRect(x+5,y+3,2,2); g.fillRect(x+7,y+4,2,2); g.setColor(shadow); g.drawLine(x+2,y+h-1,x+2,y+h); g.fillRect(x+3,y+h-2,2,2); g.fillRect(x+5,y+h-3,2,2); g.fillRect(x+7,y+h-4,2,2); g.setColor(oldColor); } else { g.setColor(highlight); g.fillRect(x+1,y+4,2,2); g.fillRect(x+3,y+3,2,2); g.fillRect(x+5,y+2,2,2); g.drawLine(x+7,y+1,x+7,y+2); g.setColor(shadow); g.fillRect(x+1,y+h-4,2,2); g.fillRect(x+3,y+h-3,2,2); g.fillRect(x+5,y+h-2,2,2); g.drawLine(x+7,y+3,x+7,y+h); g.drawLine(x+8,y+1,x+8,y+h); g.setColor(oldColor); } } }
Example 18
Source File: CSSBorder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public void paint(Polygon shape, Graphics g, Color color, int side) { g.setColor(((side + 1) % 4 < 2) == (type == Value.INSET) ? getShadowColor(color) : getLightColor(color)); g.fillPolygon(shape); }
Example 19
Source File: Circles.java From marvinproject with GNU Lesser General Public License v3.0 | 4 votes |
public void process ( MarvinImage a_imageIn, MarvinImage a_imageOut, MarvinAttributes a_attributesOut, MarvinImageMask a_mask, boolean a_previewMode ) { double l_intensity; circleWidth = (Integer)attributes.get("circleWidth"); shift = (Integer)attributes.get("shift"); circlesDistance = (Integer)attributes.get("circlesDistance"); Graphics l_graphics = a_imageOut.getBufferedImage().getGraphics(); // Gray MarvinImagePlugin l_filter = new GrayScale(); l_filter.load(); l_filter.process(a_imageIn, a_imageIn, a_attributesOut, a_mask, a_previewMode); performanceMeter.enableProgressBar("Halftone - Circles" , (a_imageIn.getHeight()/(circleWidth+circlesDistance))*(a_imageIn.getWidth()/(circleWidth+circlesDistance))); boolean[][] l_arrMask = a_mask.getMask(); int l_dif=0; for (int y = 0; y < a_imageIn.getHeight(); y+=circleWidth+circlesDistance) { for (int x = 0+l_dif; x < a_imageIn.getWidth(); x+=circleWidth+circlesDistance) { if(l_arrMask != null && !l_arrMask[x][y]){ continue; } l_intensity = getSquareIntensity(x,y,a_imageIn); l_intensity+=1.0/circleWidth; l_graphics.setColor(Color.white); l_graphics.fillRect(x,y,circleWidth+circlesDistance,circleWidth+circlesDistance); l_graphics.setColor(Color.black); l_graphics.fillArc((int)(x+(circleWidth-(l_intensity*circleWidth))/2), (int)(y+(circleWidth-(l_intensity*circleWidth))/2), (int)(l_intensity*(circleWidth)), (int)(l_intensity*(circleWidth)),1,360); } l_dif = (l_dif+shift)%circleWidth; performanceMeter.stepsFinished((a_imageIn.getWidth()/(circleWidth+circlesDistance))); } a_imageOut.updateColorArray(); performanceMeter.finish(); }
Example 20
Source File: MotifSliderUI.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void paintThumb(Graphics g) { Rectangle knobBounds = thumbRect; int x = knobBounds.x; int y = knobBounds.y; int w = knobBounds.width; int h = knobBounds.height; if ( slider.isEnabled() ) { g.setColor(slider.getForeground()); } else { // PENDING(jeff) - the thumb should be dithered when disabled g.setColor(slider.getForeground().darker()); } if ( slider.getOrientation() == JSlider.HORIZONTAL ) { g.translate(x, knobBounds.y-1); // fill g.fillRect(0, 1, w, h - 1); // highlight g.setColor(getHighlightColor()); drawHLine(g, 0, w - 1, 1); // top drawVLine(g, 0, 1, h); // left drawVLine(g, w / 2, 2, h - 1); // center // shadow g.setColor(getShadowColor()); drawHLine(g, 0, w - 1, h); // bottom drawVLine(g, w - 1, 1, h); // right drawVLine(g, w / 2 - 1, 2, h); // center g.translate(-x, -(knobBounds.y-1)); } else { g.translate(knobBounds.x-1, 0); // fill g.fillRect(1, y, w - 1, h); // highlight g.setColor(getHighlightColor()); drawHLine(g, 1, w, y); // top drawVLine(g, 1, y + 1, y + h - 1); // left drawHLine(g, 2, w - 1, y + h / 2); // center // shadow g.setColor(getShadowColor()); drawHLine(g, 2, w, y + h - 1); // bottom drawVLine(g, w, y + h - 1, y); // right drawHLine(g, 2, w - 1, y + h / 2 - 1);// center g.translate(-(knobBounds.x-1), 0); } }