Java Utililty Methods Icon

List of utility methods to do Icon

  1. HOME
  2. Java
  3. I
  4. Icon

Description

The list of methods to do Icon are organized into topic(s).

Method

ImageIcon createColorIcon(Color color)
Creates the color icon.
BufferedImage buffImage = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
Graphics g = buffImage.getGraphics();
g.setColor(color);
g.fillRect(0, 0, 16, 16);
g.setColor(Color.black);
g.drawRect(0, 0, 15, 15);
return new ImageIcon(buffImage);
Icon createColorIcon(final int width, final int height, final Color color)
Create icon of given size and color.
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setColor(color);
g.fillRect(0, 0, width, height);
g.dispose();
return new ImageIcon(image);
File createHistImage(JComponent c, Icon hd, File dir, Color bgColor, String fname)
create Hist Image
int w = c.getWidth();
int h = c.getHeight();
BufferedImage cHistImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = cHistImage.createGraphics();
g2.setColor(bgColor);
g2.fillRect(0, 0, w, h);
hd.paintIcon(c, g2, 0, 0);
File f = new File(dir, fname);
...
ImageIcon createRotatedImage(Component c, Icon icon, double rotatedAngle)
Creates a rotated version of the input image.
while (rotatedAngle < 0)
 rotatedAngle += 360;
double originalAngle = rotatedAngle % 360;
if (rotatedAngle != 0 && originalAngle == 0) {
 originalAngle = 360.0;
double angle = originalAngle % 90;
if (originalAngle != 0.0 && angle == 0.0) {
...
Image extractIconImage(Component component, Icon icon)
Extract an image from the specified icon.
Image source;
if (icon instanceof ImageIcon) {
 source = ((ImageIcon) icon).getImage();
} else if (component != null) {
 source = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = (Graphics2D) source.getGraphics();
 icon.paintIcon(component, g, 0, 0);
 g.dispose();
...
Image genImageResource(Class cls, String icon)
gen Image Resource
Image img = new ImageIcon(cls.getResource(icon)).getImage();
return img;
Image getChatIconImage()
get Chat Icon Image
Image image = new ImageIcon(
 Thread.currentThread().getContextClassLoader().getResource("images/logo-24.png")).getImage();
return image;
Object makeIcon(final Class baseClass, final Class rootClass, final String imageFile)
Utility method that creates a UIDefaults.LazyValue that creates an ImageIcon UIResource for the specified image file name.
return new UIDefaults.LazyValue() {
 public Object createValue(UIDefaults table) {
 byte[] buffer = java.security.AccessController
 .doPrivileged(new java.security.PrivilegedAction<byte[]>() {
 public byte[] run() {
 try {
 InputStream resource = null;
 Class<?> srchClass = baseClass;
...
BufferedImage scaleIcon(Image iconImage, int size)
scale Icon
BufferedImage newImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = newImage.createGraphics();
try {
 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
 g2.drawImage(iconImage, 0, 0, size, size, null);
} finally {
 g2.dispose();
return newImage;
Image toImage(Icon icon)
to Image
if (icon instanceof ImageIcon)
 return ((ImageIcon) icon).getImage();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(icon.getIconWidth(), icon.getIconHeight());
Graphics2D g = image.createGraphics();
icon.paintIcon(null, g, 0, 0);
...


AltStyle によって変換されたページ (->オリジナル) /