`

twaver for java 设置背景颜色

 
阅读更多

 /**
  * 设置背景图片
  *
  * @param ii 背景图片
  * @param width 背景的宽度
  * @param height 背景的宽度
  */
 public void setBackgroundByImageIcon(ImageIcon ii, int width, int height) {
  BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g2d = bufferedImage.createGraphics();
  if (ii != null && ii.getIconWidth() > 0 && ii.getIconHeight() > 0) {
   g2d.drawImage(ii.getImage(), 0, 0, width, height, null); // 绘制缩小后的图
  }

  g2d.dispose();
  Rectangle rect = new Rectangle(0, 0, width, height);
  TexturePaint texture = new TexturePaint(bufferedImage, rect);
  setBackground(new TextureBackground(texture));
 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics