Java Code Examples for java.awt.Graphics#fillRoundRect()
The following examples show how to use
java.awt.Graphics#fillRoundRect() .
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: LayerButtonUI.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
@Override protected void paintButtonPressed(Graphics g, AbstractButton b) { Graphics2D g2 = (Graphics2D) g; // save Graphics settings Color oldColor = g.getColor(); Object oldAA = g2.getRenderingHint(KEY_ANTIALIASING); // paint a rounded rectangle with the selection color // on the selected layer button g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); g.setColor(LayerButton.SELECTED_COLOR); g.fillRoundRect(0, 0, b.getWidth(), b.getHeight(), 10, 10); // restore Graphics settings g.setColor(oldColor); g2.setRenderingHint(KEY_ANTIALIASING, oldAA); }
Example 2
Source File: Env.java From frog with Apache License 2.0 | 6 votes |
private void drawWorld(Graphics g) { int brick; for (int x = 0; x < ENV_WIDTH; x++) for (int y = 0; y < ENV_HEIGHT; y++) { brick = bricks[x][y]; if (brick != 0) { g.setColor(Material.color(brick)); if (brick >= Material.FOOD && brick <= Material.FLY4) { g.fillRoundRect(x, y, 4, 4, 2, 2); // 点模式 食物只有一个点太小,画大一点 // g.drawString(String.valueOf(brick - Material.FOOD), x, y); // 数字雨模式 } else g.drawLine(x, y, x, y); // only 1 point } } g.setColor(Color.BLACK); }
Example 3
Source File: Client.java From JavaGame with MIT License | 5 votes |
/** * ������ * @param g */ private void drawBasic(Graphics g) { g.setColor(Constant.COLOR_BACK); g.fillRoundRect(Constant.BACK_X, Constant.BACK_Y, Constant.BACK_WIDTH, Constant.BACK_HEIGHT, 20, 20); g.setColor(Constant.COLOR_BLOCK_BACK); for(int i=1;i<=4;i++){ for(int j=1;j<=4;j++){ int xStart =Constant.BACK_X+Constant.BLOCK_SPACE*j+Constant.BLOCK_WIDTH*(j-1); int yStart = Constant.BACK_Y+Constant.BLOCK_SPACE*i+Constant.BLOCK_WIDTH*(i-1); g.fillRoundRect(xStart, yStart, Constant.BLOCK_WIDTH, Constant.BLOCK_WIDTH, 10, 10); } } }
Example 4
Source File: TMAssociationNode.java From ontopia with Apache License 2.0 | 5 votes |
/** * @param g - * The graphic context for the drawing operation. * @param string - * The String to be rendered. * @param x - * The x coordinate where the String should be positioned. * @param y - * The y coordinate where the String should be positioned. NOTE: The * text is <b>centered </b> over the given coordinates. */ private void paintToolTipText(Graphics g, String string, int x, int y) { g.setFont(this.getFont()); FontMetrics fontMetrics = g.getFontMetrics(); int a = fontMetrics.getAscent(); int h = a + fontMetrics.getDescent(); int w = fontMetrics.stringWidth(string); int xPosition = x - (w / 2); int yPosition = y - (h / 2); // Draw the background Color c = this.getBackColor(); g.setColor(c); int r = h / 2; int vPad = h / 8; int hPad = h / 4; g.fillRoundRect(xPosition - hPad, yPosition - vPad, w + (2 * hPad), h + (2 * vPad), r, r); // Draw a defined edge to the popup g.setColor(TMTopicNode.textColourForBackground(c)); g.drawRoundRect(xPosition - hPad, yPosition - vPad, w + (2 * hPad), h + (2 * vPad), r, r); // Draw the text g.drawString(string, xPosition, yPosition + a); }
Example 5
Source File: Constant.java From Logisim with GNU General Public License v3.0 | 5 votes |
@Override public void paintInstance(InstancePainter painter) { Bounds bds = painter.getOffsetBounds(); BitWidth width = painter.getAttributeValue(StdAttr.WIDTH); int intValue = painter.getAttributeValue(ATTR_VALUE).intValue(); Value v = Value.createKnown(width, intValue); Location loc = painter.getLocation(); int x = loc.getX(); int y = loc.getY(); Graphics g = painter.getGraphics(); if (painter.shouldDrawColor()) { g.setColor(BACKGROUND_COLOR); g.fillRoundRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight(), 3, 3); } if (v.getWidth() == 1) { if (painter.shouldDrawColor()) g.setColor(v.getColor()); GraphicsUtil.drawCenteredText(g, v.toString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2); } else { g.setColor(Color.BLACK); GraphicsUtil.drawCenteredText(g, v.toHexString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2); } painter.drawPorts(); }
Example 6
Source File: MSynthPainter.java From swift-k with Apache License 2.0 | 5 votes |
@Override public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { JTabbedPane t = (JTabbedPane) context.getComponent(); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (t.getSelectedIndex() == tabIndex) { g.setColor(ACCENT); g.fillRoundRect(x, y, w - 2, 5, 5, 5); g.setColor(BG); g.fillRect(x, y + 2, w - 2, 4); } }
Example 7
Source File: ColorSelector.java From stendhal with GNU General Public License v2.0 | 5 votes |
/** * Draws this component. * * @param g Where to draw to. */ @Override public void paint(Graphics g) { // use antialiasing Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = getWidth(); int height = getHeight(); int x = 0; int y = 0; int margin = margin(); // draw border getBorder().paintBorder(this, g, 0, 0, width - 1, height - 1); // draw the color g.setColor(color); g.fillRoundRect(x + margin, y + margin , width - (2 * margin), height - (2 * margin), 5, 5); // draw effect as need ButtonModel model = getModel(); if (model.isPressed()) { g.setColor(ROLLOVER_COLOR); g.fillRoundRect(x + margin, y + margin , width - (2 * margin), height - (2 * margin), 5, 5); g.fillRoundRect(x + margin, y + margin , width - (2 * margin), height - (2 * margin), 5, 5); } else if (model.isRollover()) { g.setColor(ROLLOVER_COLOR); g.fillRoundRect(x + margin, y + margin , width - (2 * margin), height - (2 * margin), 5, 5); } }
Example 8
Source File: MSynthPainter.java From swift-k with Apache License 2.0 | 5 votes |
@Override public void paintTableHeaderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { g.setColor(BG); g.fillRect(x, y, 4, h); g.fillRect(x + w - 3, y, 4, h); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(SELECTED); g.fillRoundRect(x, y, w, h, 5, 5); }
Example 9
Source File: Env.java From frog with Apache License 2.0 | 5 votes |
private void drawWorld(Graphics g) { byte brick; for (int x = 0; x < ENV_WIDTH; x++) for (int y = 0; y < ENV_HEIGHT; y++) { brick = bricks[x][y]; if (brick != 0) { g.setColor(Material.color(brick)); if (brick == Material.FOOD) g.fillRoundRect(x, y, 4, 4, 2, 2); // show food bigger else g.drawLine(x, y, x, y); // only 1 point } } g.setColor(Color.BLACK); }
Example 10
Source File: MSynthPainter.java From swift-k with Apache License 2.0 | 5 votes |
@Override public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { JTabbedPane t = (JTabbedPane) context.getComponent(); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (t.getSelectedIndex() == tabIndex) { g.setColor(BG); } else { g.setColor(INACTIVE); } g.fillRoundRect(x, y, w - 2, h, 5, 5); g.fillRect(x, y + 5, w - 2, h - 3); }
Example 11
Source File: Env.java From frog with Apache License 2.0 | 5 votes |
private void drawWorld(Graphics g) { byte brick; for (int x = 0; x < ENV_WIDTH; x++) for (int y = 0; y < ENV_HEIGHT; y++) { brick = bricks[x][y]; if (brick != 0) { g.setColor(Material.color(brick)); if (brick == Material.FOOD) g.fillRoundRect(x, y, 4, 4, 2, 2); // show food bigger else g.drawLine(x, y, x, y); // only 1 point } } g.setColor(Color.BLACK); }
Example 12
Source File: Env.java From frog with Apache License 2.0 | 5 votes |
private void drawWorld(Graphics g) { byte brick; for (int x = 0; x < ENV_WIDTH; x++) for (int y = 0; y < ENV_HEIGHT; y++) { brick = bricks[x][y]; if (brick != 0) { g.setColor(Material.color(brick)); if (brick == Material.FOOD) g.fillRoundRect(x, y, 4, 4, 2, 2); // show food bigger else g.drawLine(x, y, x, y); // only 1 point } } g.setColor(Color.BLACK); }
Example 13
Source File: ToggleButton.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
@Override public void paint(Graphics g) { // 绘制背景 super.paintBackground(g); // 处于可见状态才填充内容 if(this.isVisible()) { if (img_base == null) { g.setColor(Color.white); g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8); g.setColor(Color.black); g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8); } else { // img_base.paint(g, getX(), getY(), getWidth(), getHeight()); img_base.draw((Graphics2D)g, getX(), getY(), getWidth(), getHeight()); if (on != null) on.paint(g, getX() + 15, getY() + getHeight() - 15, getWidth() - 30, 5); g.setColor(Color.black); } } g.setFont(f); g.setColor(textColor.getColorValue()); drawText(g, textOn.getStringValue(), 0, getHeight() / 2 + fontSize / 2 - 8, CENTER); }
Example 14
Source File: GlossyTaskPaneGroupUI.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
protected void paintTitleBackground(JTaskPaneGroup group, Graphics g) { if (group.isSpecial()) { g.setColor(specialTitleBackground); g.fillRoundRect( 0, 0, group.getWidth(), ROUND_HEIGHT * 2, ROUND_HEIGHT, ROUND_HEIGHT); g.fillRect( 0, ROUND_HEIGHT, group.getWidth(), TITLE_HEIGHT - ROUND_HEIGHT); } else { Paint oldPaint = ((Graphics2D)g).getPaint(); GradientPaint gradient = new GradientPaint( 0f, 0f, //group.getWidth() / 2, titleBackgroundGradientStart, 0f, //group.getWidth(), TITLE_HEIGHT, titleBackgroundGradientEnd); ((Graphics2D)g).setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); ((Graphics2D)g).setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); ((Graphics2D)g).setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); ((Graphics2D)g).setPaint(gradient); g.fillRoundRect( 0, 0, group.getWidth(), ROUND_HEIGHT * 2, ROUND_HEIGHT, ROUND_HEIGHT); g.fillRect( 0, ROUND_HEIGHT, group.getWidth(), TITLE_HEIGHT - ROUND_HEIGHT); ((Graphics2D)g).setPaint(oldPaint); } Rectangle oldRect = g.getClipBounds(); g.setClip(0, 0, group.getWidth(), TITLE_HEIGHT); g.setColor(borderColor); g.drawRoundRect( 0, 0, group.getWidth() - 1, TITLE_HEIGHT + ROUND_HEIGHT, ROUND_HEIGHT, ROUND_HEIGHT); g.drawLine(0, TITLE_HEIGHT - 1, group.getWidth(), TITLE_HEIGHT - 1); g.setClip(oldRect); }
Example 15
Source File: ReflectedImageLabel.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Paints the component * * @param graphics The graphics context */ public void paintComponent(Graphics graphics) { // Don't paint if I'm off screen if ((getX() + getWidth() < 0) && (getY() + getHeight() < 0)) { return; } Graphics2D g = (Graphics2D) graphics; Image image = bufferedImage; int drawHeight = (int) ((double) getHeight() / 1.5); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // SiAlphaCompositemple scale only Composite oldAc = g.getComposite(); g.setComposite(alphaComposite); g.drawImage(image, 0, 0, getWidth(), getHeight(), 0, 0, image .getWidth(null), image.getHeight(null), null); // Draw text if there is any... if ((text != null) && (text.length() > 0)) { Graphics2D g2d = (Graphics2D) graphics; Rectangle2D bounds = reference.getStringBounds(text, g2d .getFontRenderContext()); double scaleFactor = (double) getWidth() / image.getWidth(null); double scaleFactor2 = (double) getWidth() / bounds.getWidth(); int fontSize = (int) Math.min(25.0 * scaleFactor, 14.0 * scaleFactor2); Font font = new Font("Arial", Font.BOLD, fontSize); g2d.setFont(font); int dx = (getWidth() - (int) font.getStringBounds(text, g2d.getFontRenderContext()).getWidth()) / 2; int dy = drawHeight + 2 * (int) (bounds.getHeight() * scaleFactor); Color background = this.getBackground(); int red = background.getRed(); int green = background.getRed(); int blue = background.getRed(); graphics.setColor(new Color(red,green,blue,96)); FontMetrics fm = g2d.getFontMetrics(); Rectangle2D rect = fm.getStringBounds(text,graphics); graphics.fillRoundRect(dx-(int)rect.getHeight()/2, dy - (int) g2d.getFontMetrics().getAscent(), (int)rect.getWidth()+((int)rect.getHeight()), fm.getAscent() + fm.getDescent(),(int)rect.getHeight(),(int)rect.getHeight()); graphics.setColor(this.getForeground()); graphics.drawString(text, dx, dy); } g.setComposite(oldAc); }
Example 16
Source File: MSynthPainter.java From swift-k with Apache License 2.0 | 4 votes |
private void paintGenericRoundedBackground(Graphics g, int x, int y, int w, int h, Color c) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(c); g.fillRoundRect(x, y, w, h, 5, 5); }
Example 17
Source File: EditView.java From DroidUIBuilder with Apache License 2.0 | 4 votes |
@Override public void paint(Graphics g) { // 绘制背景 super.paintBackground(g); // 处于可见状态才填充内容 if(this.isVisible()) { if (img_base == null) { g.setColor(Color.white); g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8); g.setColor(Color.darkGray); g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8); } else { img_base.draw((Graphics2D)g, getX(), getY(), getWidth(), getHeight()); // img.paint(g, getX(), getY(), getWidth(), getHeight()); g.setColor(Color.darkGray); } } g.setFont(f); String s; if (password.getBooleanValue()) { s = ""; for (int i = 0; i < text.getStringValue().length(); i++) s = s + '\245'; } else s = text.getStringValue(); g.setColor(textColor.getColorValue()); // g.drawString(s, getX()+pad_x/2, getY()+fontSize+pad_y/2-1); this.drawText(g, 0, (fontSize + getHeight()) / 2 - 2); // g.setColor(Color.black); // 绘制一个fucos状态下的光标样式,仅用于装饰哦 g.setColor(Color.gray); g.fillRect(getX() + pad_x / 2 - 4, getY() + (getHeight() - fontSize) / 2 - 2, 1, fontSize + 4); }
Example 18
Source File: WhylineTextField.java From whyline with MIT License | 3 votes |
public void paintComponent(Graphics g) { if(!isVisible()) return; ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setColor(UI.getControlBackColor()); g.fillRoundRect(getInsets().left / 2 + 1, getInsets().top / 2 + 1, getWidth() - getInsets().right - 1, getHeight() - getInsets().top - 1, UI.getRoundedness(), UI.getRoundedness()); super.paintComponent(g); if(label == null) label = getFont().createGlyphVector(((Graphics2D)g).getFontRenderContext(), labelText); g = g.create(); ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setColor(UI.getControlDisabledColor()); if(getText().equals("")) { int heightWithoutInsets = getHeight() - getInsets().top; int labelHeight = (int) label.getLogicalBounds().getHeight(); int offset = (heightWithoutInsets - labelHeight) / 2; int y = getHeight() - getInsets().top - offset + 1; ((Graphics2D)g).drawGlyphVector(label, getInsets().left + 4, y); } }
Example 19
Source File: WhylineScrollPane.java From whyline with MIT License | 3 votes |
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) { ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(UI.getControlCenterColor()); g.fillRoundRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, UI.getRoundedness(), UI.getRoundedness()); g.setColor(UI.getControlFrontColor()); g.drawRoundRect(trackBounds.x, trackBounds.y, trackBounds.width - 1, trackBounds.height - 1, UI.getRoundedness(), UI.getRoundedness()); }
Example 20
Source File: WhylineScrollPane.java From whyline with MIT License | 3 votes |
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds ) { ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(UI.getControlFrontColor()); g.fillRoundRect(thumbBounds.x + 2, thumbBounds.y + 2, thumbBounds.width - 4, thumbBounds.height - 4, UI.getRoundedness(), UI.getRoundedness()); }