Java Code Examples for javax.swing.ImageIcon#setImage()

The following examples show how to use javax.swing.ImageIcon#setImage() . 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: CSS.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 2
Source File: CSS.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 3
Source File: SearchComicMenuItem.java    From egdownloader with GNU General Public License v2.0 6 votes vote down vote up
public SearchComicMenuItem(String text, final EgDownloaderWindow mainWindow){
	super(text);
	this.setForeground(new Color(0,0,85));
	ImageIcon icon = IconManager.getIcon("eh");
	icon.setImage(icon.getImage().getScaledInstance(16, 16, Image.SCALE_DEFAULT));
	this.setIcon(icon);
	this.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent ae) {
			if(mainWindow.searchComicWindow == null){
				mainWindow.searchComicWindow = new SearchComicWindow(mainWindow);
			}
			SearchComicWindow scw = (SearchComicWindow) mainWindow.searchComicWindow;
			scw.setVisible(true);
			mainWindow.settingWindow.toFront();
		}
	});
	
}
 
Example 4
Source File: ImageView.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Loads the image from the URL <code>getImageURL</code>. This should
 * only be invoked from <code>refreshImage</code>.
 */
private void loadImage() {
    URL src = getImageURL();
    Image newImage = null;
    if (src != null) {
        @SuppressWarnings("unchecked")
        Dictionary<URL, Image> cache = (Dictionary)getDocument().
            getProperty(IMAGE_CACHE_PROPERTY);
        if (cache != null) {
            newImage = cache.get(src);
        }
        else {
            newImage = Toolkit.getDefaultToolkit().createImage(src);
            if (newImage != null && getLoadsSynchronously()) {
                // Force the image to be loaded by using an ImageIcon.
                ImageIcon ii = new ImageIcon();
                ii.setImage(newImage);
            }
        }
    }
    image = newImage;
}
 
Example 5
Source File: CSS.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 6
Source File: CSS.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 7
Source File: CSS.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 8
Source File: CSS.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 9
Source File: CSS.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 10
Source File: ImageUtil.java    From oim-fx with MIT License 6 votes vote down vote up
public static ImageIcon getImageIconByPath(String imagePath, int w, int h) {
    ImageIcon imageIcon = null;
    if (!"".equals(imagePath)) {
        imageIcon = getImageIcon(imagePath);
        if (null != imageIcon) {
            int width = imageIcon.getIconWidth();
            int height = imageIcon.getIconHeight();
            float xbili = (float) ((w * 1.0) / width);
            float ybili = (float) ((h * 1.0) / height);
            float bili = xbili > ybili ? ybili : xbili;
            int newwidth = (int) (width * bili);
            int newheight = (int) (height * bili);
            Image image = getImage(imagePath, newwidth, newheight);
            imageIcon.setImage(image);
        }
    }

    return imageIcon;
}
 
Example 11
Source File: CSS.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 12
Source File: CSS.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 13
Source File: CSS.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
ImageIcon getImage(URL base) {
    if (!loadedImage) {
        synchronized(this) {
            if (!loadedImage) {
                URL url = CSS.getURL(base, svalue);
                loadedImage = true;
                if (url != null) {
                    image = new ImageIcon();
                    Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
                    if (tmpImg != null) {
                        image.setImage(tmpImg);
                    }
                }
            }
        }
    }
    return image;
}
 
Example 14
Source File: ImageUtil.java    From oim-fx with MIT License 5 votes vote down vote up
public static ImageIcon getRoundedCornerImageIcon(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
	BufferedImage image = getRoundedCornerBufferedImage(imagePath, width, height, cornersWidth, cornerHeight);
	if (null == image) {
		return null;
	}
	ImageIcon icon = new ImageIcon();
	icon.setImage(image);
	return icon;
}
 
Example 15
Source File: ImageUtil.java    From oim-fx with MIT License 5 votes vote down vote up
public static ImageIcon getRoundedCornerImageIcon(Image image, int width, int height, int cornersWidth, int cornerHeight) {
    BufferedImage bufferedImage = getRoundedCornerBufferedImage(imageToBufferImage(image), width, height, cornersWidth, cornerHeight);
    if (null == bufferedImage) {
        return null;
    }
    ImageIcon icon = new ImageIcon();
    icon.setImage(bufferedImage);
    return icon;
}
 
Example 16
Source File: ImageUtil.java    From oim-fx with MIT License 5 votes vote down vote up
public static ImageIcon getRoundedCornerImageIcon(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
    BufferedImage image = getRoundedCornerBufferedImage(imagePath, width, height, cornersWidth, cornerHeight);
    if (null == image) {
        return null;
    }
    ImageIcon icon = new ImageIcon();
    icon.setImage(image);
    return icon;
}
 
Example 17
Source File: ImageUtils.java    From ocular with GNU General Public License v3.0 5 votes vote down vote up
private static void refreshViewer(Image img, AtomicInteger zoomX, AtomicInteger zoomY, ImageIcon icon, Frame frame) {
	//System.err.println(zoomX);
	//System.err.println(zoomY);
	Image newImage;
	if (zoomX.get() == 1 && zoomY.get() == 1) {
		newImage = img;
	} else {
		newImage = img.getScaledInstance((int)(img.getWidth(frame) * Math.pow(2, zoomX.get())),
				(int)(img.getHeight(frame) * Math.pow(2, zoomY.get())),
				Image.SCALE_SMOOTH);
	}
	icon.setImage(newImage);
	frame.repaint();
}
 
Example 18
Source File: UnitImageAnimation.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
    final GUI gui = getGUI();

    // Tile position should now be valid.
    if (gui.getAnimationTilePosition(this.tile) == null) {
        logger.warning("Failed attack animation for " + this.unit
            + " at tile: " + this.tile);
        return;
    }

    final Rectangle rect = gui.getAnimationTileBounds(this.tile);
    final ImageIcon icon = (ImageIcon)unitLabel.getIcon();
    for (AnimationEvent event : animation) {
        long time = System.nanoTime();
        if (event instanceof ImageAnimationEvent) {
            final ImageAnimationEvent ievent = (ImageAnimationEvent)event;
            Image image = ievent.getImage();
            if (mirror) {
                // FIXME: Add mirroring functionality to SimpleZippedAnimation
                image = ImageLibrary.createMirroredImage(image);
            }
            icon.setImage(image);
            gui.paintImmediately(rect);
            time = ievent.getDurationInMs()
                - (System.nanoTime() - time) / 1000000;
            if (time > 0) Utils.delay(time, "Animation delayed.");
        }
    }
    gui.refresh();
}
 
Example 19
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setIconImage(MainWin.icon);
		setSize(500, 300);
		setResizable(false);

		setLocationRelativeTo(this.getParent());
		setTitle("About " + AppConfig.appTitle);

		JPanel mainPanel = new JPanel(new BorderLayout());
		add(mainPanel);

		JPanel leftPanel = new JPanel();
		mainPanel.add(leftPanel, BorderLayout.WEST);

		ImageIcon iconImg = new ImageIcon(MainWin.icon);
		iconImg.setImage(iconImg.getImage().getScaledInstance((int) (iconImg.getIconWidth() * 0.5), (int) (iconImg.getIconHeight() * 0.5), Image.SCALE_SMOOTH));
		JLabel iconLabel = new JLabel(iconImg);
		iconLabel.setBorder(BorderFactory.createEmptyBorder(6, 10, 6, 10));
		leftPanel.add(iconLabel);

		HyperlinkListener hlLsnr = new HyperlinkListener() {
			@Override
			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
					return;
				// 超链接标记中必须带有协议指定,e.getURL()才能得到,否则只能用e.getDescription()得到href的内容。
				// JOptionPane.showMessageDialog(InfoDialog.this, "URL:"+e.getURL()+"\nDesc:"+ e.getDescription());
				URL linkUrl = e.getURL();
				if (linkUrl != null) {
					try {
						Desktop.getDesktop().browse(linkUrl.toURI());
					} catch (Exception e1) {
						e1.printStackTrace();
						JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "无法打开超链接:" + linkUrl + "\n详情:" + e1, JOptionPane.ERROR_MESSAGE);
					}
				} else {
					JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "超链接信息不完整:" + e.getDescription() + "\n请确保链接带有协议信息,如http://,mailto:", JOptionPane.ERROR_MESSAGE);
				}
			}
		};

		JTextPane infoArea = new JTextPane();
		//设置css单位(px/pt)和chrome一致
		infoArea.putClientProperty(JTextPane.W3C_LENGTH_UNITS, true);
		infoArea.addHyperlinkListener(hlLsnr);
		infoArea.setContentType("text/html");
		infoArea.setText(getInfo());
		infoArea.setEditable(false);
		infoArea.setBorder(BorderFactory.createEmptyBorder(2, 10, 6, 10));
		infoArea.setFocusable(false);

		JScrollPane infoAreaScrollPane = new JScrollPane(infoArea);
		infoAreaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		infoAreaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		infoAreaScrollPane.getViewport().setBackground(Color.WHITE);
		mainPanel.add(infoAreaScrollPane, BorderLayout.CENTER);

	}
 
Example 20
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setIconImage(MainWin.icon);
		setSize(500, 300);
		setResizable(false);

		setLocationRelativeTo(this.getParent());
		setTitle("About " + AppConfig.appTitle);

		JPanel mainPanel = new JPanel(new BorderLayout());
		add(mainPanel);

		JPanel leftPanel = new JPanel();
		mainPanel.add(leftPanel, BorderLayout.WEST);

		ImageIcon iconImg = new ImageIcon(MainWin.icon);
		iconImg.setImage(iconImg.getImage().getScaledInstance((int) (iconImg.getIconWidth() * 0.5), (int) (iconImg.getIconHeight() * 0.5), Image.SCALE_SMOOTH));
		JLabel iconLabel = new JLabel(iconImg);
		iconLabel.setBorder(BorderFactory.createEmptyBorder(6, 10, 6, 10));
		leftPanel.add(iconLabel);

		HyperlinkListener hlLsnr = new HyperlinkListener() {
			@Override
			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
					return;
				// 超链接标记中必须带有协议指定,e.getURL()才能得到,否则只能用e.getDescription()得到href的内容。
				// JOptionPane.showMessageDialog(InfoDialog.this, "URL:"+e.getURL()+"\nDesc:"+ e.getDescription());
				URL linkUrl = e.getURL();
				if (linkUrl != null) {
					try {
						Desktop.getDesktop().browse(linkUrl.toURI());
					} catch (Exception e1) {
						e1.printStackTrace();
						JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "无法打开超链接:" + linkUrl + "\n详情:" + e1, JOptionPane.ERROR_MESSAGE);
					}
				} else {
					JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "超链接信息不完整:" + e.getDescription() + "\n请确保链接带有协议信息,如http://,mailto:", JOptionPane.ERROR_MESSAGE);
				}
			}
		};

		JTextPane infoArea = new JTextPane();
		//设置css单位(px/pt)和chrome一致
		infoArea.putClientProperty(JTextPane.W3C_LENGTH_UNITS, true);
		infoArea.addHyperlinkListener(hlLsnr);
		infoArea.setContentType("text/html");
		infoArea.setText(getInfo());
		infoArea.setEditable(false);
		infoArea.setBorder(BorderFactory.createEmptyBorder(2, 10, 6, 10));
		infoArea.setFocusable(false);

		JScrollPane infoAreaScrollPane = new JScrollPane(infoArea);
		infoAreaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		infoAreaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		infoAreaScrollPane.getViewport().setBackground(Color.WHITE);
		mainPanel.add(infoAreaScrollPane, BorderLayout.CENTER);

	}