java.awt.Graphics2D.drawRoundRect()方法的使用及代码示例

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

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

Graphics2D.drawRoundRect介绍

暂无

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

public void drawRoundRectangle( int x, int y, int width, int height, int circleWidth, int circleHeight ) {
 gc.drawRoundRect( x + xOffset, y + yOffset, width, height, circleWidth, circleHeight );
}

代码示例来源:origin: pentaho/pentaho-kettle

public void drawRoundRectangle( int x, int y, int width, int height, int circleWidth, int circleHeight ) {
 gc.drawRoundRect( x + xOffset, y + yOffset, width, height, circleWidth, circleHeight );
}

代码示例来源:origin: bonnyfone/vectalign

graphics.setColor(getForeground());
graphics.setStroke(new BasicStroke(strokeSize));
graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height);

代码示例来源:origin: jphp-group/jphp

@Signature
public void roundRect(int x, int y, int width, int height, int arcWidth, int arcHeight, DrawOptions options) {
  applyOptions(options);
  if (options.isOutline()) {
    gc.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  } else {
    gc.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
  }
}

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

g2.drawRoundRect( 1, 1, getWidth()-2 - 1, getHeight()-2 - 1, 2,2 );
g2.setColor( white );
g2.drawRoundRect( 1 + 1, 1 + 1, getWidth()-2 - 3, getHeight()-2 - 3, 2,2 );
g2.drawRoundRect( x, y, w - 1, h - 1, 2,2 );
g2.setColor( white );
g2.drawRoundRect( x + 1, y + 1, w - 3, h - 3, 2,2 );

代码示例来源:origin: apache/pdfbox

@Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
{
  groupG2D.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
  alphaG2D.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}

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

public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
  delegate.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}

代码示例来源:origin: apache/geode

public void highlight(Graphics2D g) {
 Rectangle bounds = g.getClipBounds();
 if (startY > bounds.getMaxY() || startY + height < bounds.getMinY()) {
  return;
 }
 int x = line.getX();
 int width = line.getWidth();
 g.drawRoundRect(x, startY, width, height, ARC_SIZE, ARC_SIZE);
}

代码示例来源:origin: RaiMan/SikuliX2

private void drawRect(int type, Graphics2D g2d, int x, int y, int w, int h, int stroke, Color color) {
 g2d.setColor(color);
 int offset = stroke / 2;
 int margin = -stroke;
 if (type == AROUND) {
  stroke = ((stroke + 1) / 2) * 2;
  offset = -stroke / 2;
  margin = stroke;
 }
 g2d.setStroke(new BasicStroke(stroke));
 if (type == ROUNDED) {
  g2d.drawRoundRect(x + offset, y + offset, w + margin, h + margin, corner, corner);
 } else {
  g2d.drawRect(x + offset, y + offset, w + margin, h + margin);
 }
}

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

private void paintBorder(Graphics g, Dimension size) {
  Graphics2D g2d = createGraphics(g);
  try {
    g2d.setStroke(new BasicStroke(2f));
    g2d.setColor(BORDER_COLOR);
    g2d.drawRoundRect(0, 0, size.width-1, size.height-1, 9, 9);
  } finally {
    g2d.dispose();
  }
}

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

private void paintBorder(Graphics g, Dimension size) {
  Graphics2D g2d = createGraphics(g);
  try {
    g2d.setStroke(new BasicStroke(1f));
    g2d.setColor(Border.COLOR);
    g2d.drawRoundRect(0, 0, size.width-1, size.height-1, Border.RADIUS, Border.RADIUS);
  } finally {
    g2d.dispose();
  }
}

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

private static void paintTooltip(Graphics2D g, Point2D point, String text) {
  FontMetrics fontMetrics = g.getFontMetrics();
  int textWidth = fontMetrics.stringWidth(text);
  int verticalOffset = 10;
  Rectangle r = new Rectangle((int) point.getX(), (int) point.getY() + verticalOffset, textWidth, fontMetrics.getHeight());
  r.grow(4, 3);
  g.setColor(TOOLTIP_STROKE_COLOR);
  g.drawRoundRect(r.x, r.y, r.width, r.height, 8, 8);
  g.setColor(TOOLTIP_BACKGROUND_COLOR);
  g.fillRoundRect(r.x, r.y, r.width, r.height, 8, 8);
  g.setColor(TOOLTIP_TEXT_COLOR);
  g.drawString(text, (float) point.getX(), (float) point.getY() + fontMetrics.getAscent() + verticalOffset);
}

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

JPanel p = new JPanel() {
  @Override
  protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Dimension arcs = new Dimension(15,15); //Border corners arcs {width,height}, change this to whatever you want
   int width = getWidth();
   int height = getHeight();
   Graphics2D graphics = (Graphics2D) g;
   graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   //Draws the rounded panel with borders.
   graphics.setColor(getBackground());
   graphics.fillRoundRect(0, 0, width-1, height-1, arcs.width, arcs.height);//paint background
   graphics.setColor(getForeground());
   graphics.drawRoundRect(0, 0, width-1, height-1, arcs.width, arcs.height);//paint border
  }
};

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

private static void drawColor(Graphics2D g, Color c, int x, int y) {
  g.setColor(java.awt.Color.WHITE);
  g.fillRoundRect(x, y, COLOR_SIZE + 6, COLOR_SIZE + 6, 3, 3);
  g.setColor(java.awt.Color.LIGHT_GRAY);
  g.drawRoundRect(x, y, COLOR_SIZE + 6, COLOR_SIZE + 6, 3, 3);
  g.setColor(c.getAwtColor());
  g.fillRect(x + 3, y + 3, COLOR_SIZE, COLOR_SIZE);
}

代码示例来源:origin: magefree/mage

protected void drawDetailed(Graphics2D g) {
  // Get the size of the card
  int width = getWidth();
  int height = getHeight();
  
  g.setColor(Color.black);
  g.drawRoundRect(0, 0, width, height, 4, 4);
  g.setColor(Color.white);
  g.setFont(new Font("Arial", Font.PLAIN, NAME_FONT_MAX_SIZE));
  g.drawString(card.getName(), 0, 0);
  Logger.getLogger(Card.class).info("Drawing");
}

代码示例来源:origin: vsch/flexmark-java

public static BufferedImage addBorder(BufferedImage image, Color borderColor, int borderWidth, int cornerRadius) {
  int w = image.getWidth() + borderWidth * 2;
  int h = image.getHeight() + borderWidth * 2;
  BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
  //BufferedImage output = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2 = output.createGraphics();
  g2.setColor(borderColor);
  g2.drawImage(image, borderWidth, borderWidth, image.getWidth(), image.getHeight(), null);
  //UIUtil.drawImage(g2, image, 0, 0, null);
  g2.setStroke(new BasicStroke(borderWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, borderWidth));
  g2.setRenderingHint(
      RenderingHints.KEY_ANTIALIASING,
      RenderingHints.VALUE_ANTIALIAS_ON
  );
  int width = w - borderWidth - 1;
  int height = h - borderWidth - 1;
  int halfBorder = borderWidth / 2;
  if (cornerRadius > 0) {
    int adjustedRadius = cornerRadius + borderWidth;
    g2.drawRoundRect(halfBorder, halfBorder, width, height, adjustedRadius, adjustedRadius);
  } else {
    g2.drawRect(halfBorder, halfBorder, width, height);
  }
  g2.dispose();
  //output.setRGB(3, 3, 123);
  return output;
}

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

/**
 * Icon for generic Geometry or Geometry Collection.
 *
 * @param color
 * @param fill
 * @return Icon
 */
public static BufferedImage geometry(final Color color, final Color fill) {
  BufferedImage bi =
      new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.TYPE_INT_ARGB);
  Graphics2D gc = (Graphics2D) bi.getGraphics();
  gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  Stroke stroke = new BasicStroke(1);
  gc.setStroke(stroke);
  Color c = color;
  Color f = fill;
  if (c == null) c = Color.BLACK;
  if (f == null) f = Color.LIGHT_GRAY;
  gc.setColor(f);
  gc.fillRoundRect(2, 1, 13, 13, 2, 2);
  gc.setColor(c);
  gc.drawRoundRect(2, 1, 13, 13, 2, 2);
  return bi;
}

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

JFrame f = new JFrame();
f.setLayout(null);
f.setDefaultCloseOperation(3);
f.setSize(500, 500);
JPanel p = new JPanel() {
  @Override
  protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Dimension arcs = new Dimension(15,15);
   int width = getWidth();
   int height = getHeight();
   Graphics2D graphics = (Graphics2D) g;
   graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   //Draws the rounded opaque panel with borders.
   graphics.setColor(getBackground());
   graphics.fillRoundRect(0, 0, width-1, height-1, arcs.width, arcs.height);//paint background
   graphics.setColor(getForeground());
   graphics.drawRoundRect(0, 0, width-1, height-1, arcs.width, arcs.height);//paint border
  }
};
p.setBounds(10,10,100,30);
p.setOpaque(false);
f.getContentPane().setBackground(Color.red);
f.add(p);
f.show();

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

private void paintRoundBorder(Graphics2D g, AbstractButton b) {
  Color color = look.colors().shadow();
  g.setColor(color);
  g.drawRoundRect(0, 0, b.getWidth()-1, b.getHeight()-1, 4, 4);
}

代码示例来源:origin: winder/Universal-G-Code-Sender

@Override
protected void paintComponent(Graphics gfx) {
  super.paintComponent(gfx);
  Dimension arcs = new Dimension(radius, radius);
  Graphics2D gfx2d = (Graphics2D) gfx;
  gfx2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  gfx2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
  // background
  Color background = getBackground();
  if (!isEnabled() && backgroundDisabled != null) {
    background = backgroundDisabled;
  } else if (mousePressed && pressedBackground != null && isEnabled()) {
    background = pressedBackground;
  } else if (mouseOver && hoverBackground != null && isEnabled()) {
    background = hoverBackground;
  }
  Color foreground = getForeground();
  if (!isEnabled() && foregroundDisabled != null) {
    foreground = foregroundDisabled;
  }
  gfx2d.setColor(background);
  gfx2d.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcs.width, arcs.height);
  // border
  gfx2d.setColor(foreground);
  gfx2d.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcs.width, arcs.height);
}

相关文章

Graphics2D类方法