javax.swing.Icon类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(177)

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

Icon介绍

暂无

代码示例

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

public BufferedImage getImage(double scale, Color foregroundColor, Color backgroundColor)
    throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException,
    IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  final Icon icon = buildIcon(foregroundColor);
  final BufferedImage image = new BufferedImage((int) (icon.getIconWidth() * scale),
      (int) (icon.getIconHeight() * scale), BufferedImage.TYPE_INT_ARGB);
  final Graphics2D g2 = image.createGraphics();
  g2.scale(scale, scale);
  if (backgroundColor != null) {
    g2.setColor(backgroundColor);
    g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
  }
  icon.paintIcon(null, g2, 0, 0);
  return image;
}

代码示例来源:origin: skylot/jadx

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  int w = getIconWidth();
  int h = getIconHeight();
  icon.paintIcon(c, g, x, y);
  int k = 0;
  for (Icon subIcon : icons) {
    int dx = (int) (OVERLAY_POS[k++] * (w - subIcon.getIconWidth()));
    int dy = (int) (OVERLAY_POS[k++] * (h - subIcon.getIconHeight()));
    subIcon.paintIcon(c, g, x + dx, y + dy);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

MergedIcon(Icon icon1, Icon icon2, int xMerge, int yMerge) {
  assert icon1 != null;
  assert icon2 != null;
  this.icon1 = icon1;
  this.icon2 = icon2;
  if (xMerge == -1) {
    xMerge = icon1.getIconWidth() - icon2.getIconWidth();
  }
  if (yMerge == -1) {
    yMerge = icon1.getIconHeight() - icon2.getIconHeight();
  }
  this.xMerge = xMerge;
  this.yMerge = yMerge;
}

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

graphics.setComposite(composite);
  double dx = -image.getWidth() * gstyle.getAnchorPointX() + gstyle.getDisplacementX();
  double dy = -image.getHeight() * gstyle.getAnchorPointY() + gstyle.getDisplacementY();
  renderImage(graphics, x, y, dx, dy, image, rotation, composite, isLabelObstacle);
} else if (style instanceof MarkStyle2D) {
  if (transformedShape != null) {
    if (ms2d.getFill() != null) {
      graphics.setPaint(ms2d.getFill());
      graphics.fill(transformedShape);
  float dx = -(icon.getIconWidth() * icons.getAnchorPointX()) + icons.getDisplacementX();
  float dy = -(icon.getIconHeight() * icons.getAnchorPointY()) + icons.getDisplacementY();
  markAT.translate(dx, dy);
  try {
    graphics.setTransform(markAT);
    icon.paintIcon(null, graphics, 0, 0);
  } finally {
    graphics.setTransform(temp);
    labelCache.put(
        new Rectangle2D.Double(
            x + dx, y + dy, icon.getIconWidth(), icon.getIconHeight()));

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

public Icon getHostIcon() {
  if (hostIcon != null) return hostIcon;
  BufferedImage img = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = (Graphics2D) img.getGraphics();
  Icon icon = new ImageIcon(host.getIconFile());
  float factor = 64f / icon.getIconHeight();
  g.scale(factor, factor);
  icon.paintIcon(null, g, 0, 0);
  hostIcon = new ImageIcon(img);
  return hostIcon;
}

代码示例来源:origin: com.gitlab.cdc-java.ui/cdc-ui-swing

public static Image iconToImage(Icon icon) {
  if (icon instanceof ImageIcon) {
    return ((ImageIcon) icon).getImage();
  } else {
    final int width = icon.getIconWidth();
    final int height = icon.getIconHeight();
    final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    final Graphics2D g = image.createGraphics();
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
  }
}

代码示例来源:origin: org.bidib.jbidib.com.vldocking/vldocking

private Icon createDisabledIcon() {
  if(defaultIcon instanceof ImageIcon) {
    Image i = GrayFilter.createDisabledImage(((ImageIcon) defaultIcon).getImage());
    return new ImageIcon(i);
  } else {
    BufferedImage bi = new BufferedImage(defaultIcon.getIconWidth(), defaultIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.createGraphics();
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, defaultIcon.getIconWidth(), defaultIcon.getIconHeight());
    defaultIcon.paintIcon(null, g, 0, 0);
    g.dispose();
    Image i = GrayFilter.createDisabledImage(bi);
    return new ImageIcon(i);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

public Dimension getPreferredSize() {
    int w = 0;
    int h = 0;
    Graphics g = PropUtils.getScratchGraphics(this);
    FontMetrics fm = g.getFontMetrics(getFont());
    if (getIcon() != null) {
      w = getIcon().getIconWidth();
      h = getIcon().getIconHeight();
    }
    if (getBorder() != null) {
      Insets ins = getBorder().getBorderInsets(this);
      w += (ins.left + ins.right);
      h += (ins.bottom + ins.top);
    }
    w += (fm.stringWidth(getText()) + 22);
    h = Math.max(fm.getHeight(), h) + 2;
    return new Dimension(w, h);
  }
}

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

SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    ImageIcon imageIcon = new ImageIcon(url);
    JLabel imageLabel = new JLabel(
      text,
    BufferedImage bi = new BufferedImage(
      icon.getIconWidth(),
      icon.getIconHeight(),
      BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.createGraphics();
    icon.paintIcon(null, g, 0,0);
    g.setColor(Color.WHITE);
    g.drawString(text,10,20);
    g.dispose();
      new JLabel(new ImageIcon(bi)));

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

+ ". You can override this limit by setting the org.geotools.render.random.maxCount system property");
if (icon != null && (icon.getIconWidth() > tileSize || icon.getIconHeight() > tileSize)) {
  throw new IllegalArgumentException(
      "Cannot perform random image disposition, image size "
          + icon.getIconWidth()
          + "x"
          + icon.getIconHeight()
          + " exceeds randomized tile size: "
          + tileSize);
BufferedImage image = new BufferedImage(tileSize, tileSize, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2d = image.createGraphics();
Object oldInterpolationValue = g2d.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
if (randomRotation && icon != null) {
  g2d.setRenderingHint(
      RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
AffineTransform originalTransform = g2d.getTransform();
try {
  try {
          g2d.setTransform(originalTransform);
          g2d.transform(transform);
          icon.paintIcon(null, g2d, 0, 0);
        } else if (shape != null) {
          factory.fillDrawMark(

代码示例来源:origin: mguessan/davmail

protected Image getImageForIcon(Icon icon) {
    BufferedImage bufferedimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufferedimage.getGraphics();
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return bufferedimage;
  }
}

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

public void paintIcon(Component c, Graphics g, int x, int y) {
    BufferedImage img =
        new BufferedImage(
            icon.getIconWidth(),
            icon.getIconHeight(),
            BufferedImage.TYPE_INT_ARGB);
    // we can cache the img when aaime gets out a profiler and tells us it is
    // worthwhile
    icon.paintIcon(c, img.getGraphics(), 0, 0);
    if (c != null) {
      g.drawImage(img, x, y, size, size, c.getBackground(), c);
    } else {
      g.drawImage(img, x, y, size, size, c);
    }
  }
};

代码示例来源:origin: net.sf.nimrod/nimrod-laf

static Icon reescala( Icon ic, int maxW, int maxH) {
 if ( ic == null ) {
  return null;
 }
 if ( ic.getIconHeight() == maxH && ic.getIconWidth() == maxW ) {
  return ic;
 }
 
 BufferedImage bi = new BufferedImage( ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
 
 Graphics g = bi.createGraphics();
 ic.paintIcon( null, g, 0, 0);
 g.dispose();
 
 Image bf = bi.getScaledInstance( maxW, maxH, Image.SCALE_SMOOTH);
 
 return new ImageIcon( bf);
}

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

m_tree.putClientProperty("JTree.lineStyle", "Angled");
  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception evt) {}
new FileTreeViewer();
m_borderSelectionColor = UIManager.getColor(
    "Tree.selectionBorderColor");
setOpaque(false);
  setIcon(null);
setFont(tree.getFont());
setForeground(sel ? m_textSelectionColor : 
  m_textNonSelectionColor);
Icon icon = getIcon();
g.setColor(bColor);
int offset = 0;
if(icon != null && getText() != null) 
  offset = (icon.getIconWidth() + getIconTextGap());
g.fillRect(offset, 0, getWidth() - 1 - offset,
    getHeight() - 1);
  g.setColor(m_borderSelectionColor);
  g.drawRect(offset, 0, getWidth()-1-offset, getHeight()-1);

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

.newInstance(ctx, fontAsShapes);
dimension = new Dimension(icon.getIconWidth(), icon.getIconHeight());
  g2.setColor(backgroundColor);
  g2.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight());
icon.paintIcon(null, g2, 0, 0);

代码示例来源:origin: skylot/jadx

public ProgressPanel(final MainWindow mainWindow, boolean showCancelButton) {
  progressLabel = new JLabel();
  progressBar = new JProgressBar(0, 100);
  progressBar.setIndeterminate(true);
  progressBar.setStringPainted(false);
  progressLabel.setLabelFor(progressBar);
  setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  setVisible(false);
  add(progressLabel);
  add(progressBar);
  if (showCancelButton) {
    JButton cancelButton = new JButton(ICON_CANCEL);
    cancelButton.setPreferredSize(new Dimension(ICON_CANCEL.getIconWidth(), ICON_CANCEL.getIconHeight()));
    cancelButton.setToolTipText("Cancel background jobs");
    cancelButton.setBorderPainted(false);
    cancelButton.setFocusPainted(false);
    cancelButton.setContentAreaFilled(false);
    cancelButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        mainWindow.cancelBackgroundJobs();
      }
    });
    add(cancelButton);
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

public static Image getImage(Icon icon) {

    if (icon instanceof ImageIcon) {
      return ((ImageIcon)icon).getImage();
    }

    int width = icon.getIconWidth();
    int height = icon.getIconHeight();
    BufferedImage image = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    icon.paintIcon(null, g2, 0, 0);
    return image;
  }
}

代码示例来源:origin: com.github.axet/desktop

public static BufferedImage createBitmap(Icon icon) {
  BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = bi.createGraphics();
  g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
  icon.paintIcon(null, g, 0, 0);
  g.dispose();
  return bi;
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-common

public static Icon resize(final Icon _ic, final int _newWidth, final int _newHeight) {
 if (_ic.getIconHeight() == _newHeight && _ic.getIconWidth() == _newWidth) { return _ic; }
 final BufferedImage im = new BufferedImage(_ic.getIconWidth(), _ic.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
 final Graphics g = im.createGraphics();
 _ic.paintIcon(BuLib.HELPER, g, 0, 0);
 final Image res = resize(im, _newWidth, _newHeight);
 im.flush();
 return new ImageIcon(res);
}

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

if (img.getImage() instanceof BufferedImage) {
    BufferedImage image = (BufferedImage) img.getImage();
    return new GraphicStyle2D(image, 0, 0);
    new BufferedImage(
        icon.getIconWidth() + border * 2,
        icon.getIconHeight() + border * 2,
        BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = (Graphics2D) result.getGraphics();
g.setRenderingHints(renderingHints);
icon.paintIcon(null, g, 1, 1);
g.dispose();

相关文章