List of usage examples for javax.swing ImageIcon getImage
@Transient
public Image getImage()
Image
. From source file:edu.ku.brc.specify.ui.LoanReturnDlg.java
/** * Constructor.//from w ww. ja v a 2 s . c om * @param loan the loan */ public LoanReturnDlg(final Loan loan) { this.loan = loan; ImageIcon appIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$ if (appIcon != null) { setIconImage(appIcon.getImage()); } }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
private void save() { try {//from w w w . j a v a 2s. c om Entigrator entigrator = console.getEntigrator(entihome$); Sack webset = entigrator.getEntityAtKey(entityKey$); webset.putElementItem("web", new Core(nameField.getText(), webLinkKey$, addressField.getText())); String login$ = loginField.getText(); String password$ = passwordField.getText(); if (login$ != null || password$ != null) webset.putElementItem("web.login", new Core(login$, webLinkKey$, password$)); ImageIcon imageIcon = (ImageIcon) iconIcon.getIcon(); if (imageIcon != null) { BufferedImage bi = (BufferedImage) imageIcon.getImage(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, "png", baos); byte[] res = baos.toByteArray(); String icon$ = Base64.encodeBase64String(res); webset.putElementItem("web.icon", new Core(null, webLinkKey$, icon$)); } entigrator.save(webset); } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } }
From source file:generadorqr.jifrNuevoQr.java
void CargarImagen(JLabel label, Integer identificador) { int resultado; // ventana = new CargarFoto(); JFileChooser jfchCargarfoto = new JFileChooser(); FileNameExtensionFilter filtro = new FileNameExtensionFilter("JPG", "jpg"); jfchCargarfoto.setFileFilter(filtro); resultado = jfchCargarfoto.showOpenDialog(null); if (JFileChooser.APPROVE_OPTION == resultado) { fichero = jfchCargarfoto.getSelectedFile(); try {/*from w w w. jav a 2 s .c o m*/ tempImagen[identificador] = fichero.getPath(); tempNombreArchivo[identificador] = fichero.getName(); ImageIcon icon = new ImageIcon(fichero.toString()); Icon icono = new ImageIcon(icon.getImage().getScaledInstance(label.getWidth(), label.getHeight(), Image.SCALE_DEFAULT)); label.setText(null); label.setIcon(icono); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error abriendo la imagen" + ex); } } }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
/** * The default constructor./*from w ww . ja v a 2s. com*/ */ public JWeblinkEditor() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }; setLayout(gridBagLayout); String icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "globe.png"); byte[] ba = Base64.decodeBase64(icon$); ImageIcon icon = new ImageIcon(ba); Image image = icon.getImage().getScaledInstance(24, 24, 0); icon.setImage(image); JLabel iconLabel = new JLabel("Icon"); c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; c.weighty = 0; c.gridx = 0; c.gridy = 0; add(iconLabel, c); iconLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showIconMenu(e); } }); iconIcon = new JLabel(); iconIcon.setIcon(icon); c_0 = new GridBagConstraints(); c_0.anchor = GridBagConstraints.WEST; c_0.insets = new Insets(0, 5, 5, 0); c.anchor = GridBagConstraints.WEST; c_0.gridx = 1; c_0.gridy = 0; add(iconIcon, c_0); iconIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showIconMenu(e); } }); JLabel lblName = new JLabel("Name"); c_1 = new GridBagConstraints(); c_1.insets = new Insets(5, 5, 5, 5); c_1.fill = GridBagConstraints.HORIZONTAL; c_1.gridx = 0; c_1.gridy = 1; add(lblName, c_1); nameField = new JTextField(); c_2 = new GridBagConstraints(); c_2.insets = new Insets(0, 5, 5, 0); c_2.fill = GridBagConstraints.HORIZONTAL; c_2.gridx = 1; c_2.gridy = 1; add(nameField, c_2); JLabel lblUrl = new JLabel("Address"); c_3 = new GridBagConstraints(); c_3.insets = new Insets(5, 5, 5, 5); c_3.fill = GridBagConstraints.HORIZONTAL; c_3.gridx = 0; c_3.gridy = 2; add(lblUrl, c_3); addressField = new JTextField(); c_4 = new GridBagConstraints(); c_4.insets = new Insets(0, 5, 5, 0); c_4.fill = GridBagConstraints.HORIZONTAL; c_4.gridx = 1; c_4.gridy = 2; add(addressField, c_4); JLabel lblLogin = new JLabel("Login"); c_5 = new GridBagConstraints(); c_5.insets = new Insets(5, 5, 5, 5); c_5.fill = GridBagConstraints.HORIZONTAL; c_5.gridx = 0; c_5.gridy = 3; add(lblLogin, c_5); lblLogin.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showLoginMenu(e); } }); loginField = new JTextField(); c_6 = new GridBagConstraints(); c_6.insets = new Insets(0, 5, 5, 0); c_6.fill = GridBagConstraints.HORIZONTAL; c_6.gridx = 1; c_6.gridy = 3; add(loginField, c_6); JLabel lblPassword = new JLabel("Password"); c_7 = new GridBagConstraints(); c_7.insets = new Insets(5, 5, 5, 5); c_7.fill = GridBagConstraints.HORIZONTAL; c_7.gridx = 0; c_7.gridy = 4; add(lblPassword, c_7); lblPassword.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showPasswordMenu(e); } }); passwordField = new JTextField(); c_8 = new GridBagConstraints(); c_8.insets = new Insets(0, 5, 5, 0); c_8.fill = GridBagConstraints.HORIZONTAL; c_8.gridx = 1; c_8.gridy = 4; add(passwordField, c_8); JPanel bottom = new JPanel(); c_9 = new GridBagConstraints(); c_9.weighty = 1; c_9.fill = GridBagConstraints.VERTICAL; c_9.gridx = 0; c_9.gridy = 5; add(bottom, c_9); }
From source file:com.loy.MainFrame.java
private void systemTray() { if (SystemTray.isSupported()) { ImageIcon icon = new ImageIcon(image); PopupMenu popupMenu = new PopupMenu(); MenuItem itemShow = new MenuItem("Show"); MenuItem itemExit = new MenuItem("Exit"); itemExit.addActionListener(new ActionListener() { @Override// ww w. j a v a 2 s .c o m public void actionPerformed(ActionEvent e) { killProcess(); System.exit(0); } }); itemShow.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(true); } }); popupMenu.add(itemShow); popupMenu.add(itemExit); TrayIcon trayIcon = new TrayIcon(icon.getImage(), "E-MICRO-SERVICE-START", popupMenu); SystemTray sysTray = SystemTray.getSystemTray(); try { sysTray.add(trayIcon); } catch (AWTException e1) { } } }
From source file:it.geosolutions.opensdi2.mvc.BaseFileManager.java
/** * Generate a image thumb/*from www . ja va 2 s .c o m*/ * * @param toServeUp * @param thumbPath * @return * @throws IOException */ protected InputStream getImageThumb(File toServeUp, String thumbPath) throws IOException { BufferedImage image = ImageIO.read(toServeUp); ImageIcon img = new ImageIcon( new ImageIcon(image).getImage().getScaledInstance(THUMB_W, THUMB_H, Image.SCALE_FAST)); BufferedImage bimage = new BufferedImage(THUMB_W, THUMB_H, BufferedImage.TYPE_INT_RGB); // Copy image to buffered image Graphics g = bimage.createGraphics(); g.drawImage(img.getImage(), 0, 0, null); g.dispose(); ImageIO.write(bimage, "jpg", new File(thumbPath)); return new java.io.FileInputStream(thumbPath); }
From source file:lol.search.RankedStatsPage.java
private JPanel headerPanel() { //init spacers for header for (int i = 0; i < 10; i++) { JLabel label = new JLabel("--"); label.setForeground(new Color(0, 0, 0, 0)); spacers.add(label);/*w w w. j a v a 2 s.c om*/ } //header -- to set this semi-transparent i had to remove setOpaque and replace with setBackground(...) JPanel headerPanel = new JPanel(); headerPanel.setLayout(new BorderLayout()); //headerPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); headerPanel.setBackground(backgroundColor); headerPanel.setPreferredSize(headerDimension); //back button JPanel buttonHolder = new JPanel(); ImageIcon buttonImage = new ImageIcon("assets\\other\\button.png"); ImageIcon buttonPressedImage = new ImageIcon("assets\\other\\buttonPressed.png"); Image tempImage = buttonImage.getImage(); Image newTempImg = tempImage.getScaledInstance(75, 35, Image.SCALE_SMOOTH); buttonImage = new ImageIcon(newTempImg); JButton backButton = new JButton("BACK"); backButton.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 10)); //custom font backButton.setForeground(Color.WHITE); //text color backButton.setBackground(new Color(0, 0, 0, 0)); backButton.setBorder(BorderFactory.createLineBorder(Color.BLACK)); backButton.setHorizontalTextPosition(AbstractButton.CENTER); backButton.setPreferredSize(new Dimension(75, 35)); //pressed button Image tempImage2 = buttonPressedImage.getImage(); Image newTempImg2 = tempImage2.getScaledInstance(75, 35, Image.SCALE_SMOOTH); buttonPressedImage = new ImageIcon(newTempImg2); backButton.setIcon(buttonImage); backButton.setRolloverIcon(buttonPressedImage); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //button pressed System.out.println("Going back...\n"); masterFrame.getContentPane().removeAll(); masterFrame.revalidate(); masterFrame.repaint(); MainPage MAIN_PAGE = new MainPage(masterFrame, summonerName); } }); buttonHolder.add(backButton); buttonHolder.setOpaque(false); headerPanel.add(buttonHolder, BorderLayout.LINE_START); //centerpanel JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(1, 2)); centerPanel.setOpaque(false); //centerPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); //rightcenter JPanel rightCenter = new JPanel(); rightCenter.setOpaque(false); rightCenter.setLayout(new GridLayout(2, 1)); //top center panel JPanel topCenter = new JPanel(); topCenter.setOpaque(false); topCenter.setLayout(new BoxLayout(topCenter, BoxLayout.X_AXIS)); //profile icon JPanel proIconPanel = new JPanel(); proIconPanel.setOpaque(false); proIconPanel.setLayout(new BoxLayout(proIconPanel, BoxLayout.Y_AXIS)); JLabel profileIconLabel = new JLabel(this.profileIcon); //profileIconLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); profileIconLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); proIconPanel.add(profileIconLabel); centerPanel.add(proIconPanel); //empty spacer topCenter.add(spacers.get(0)); //summoner name JLabel summonerNameLabel = new JLabel(this.summonerName); summonerNameLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 15)); //custom font summonerNameLabel.setForeground(Color.WHITE); //text color summonerNameLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(summonerNameLabel); //empty spacer topCenter.add(spacers.get(1)); //tier JLabel tierLabel = new JLabel(this.tier); tierLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 13)); //custom font tierLabel.setForeground(new Color(219, 219, 219)); //text color tierLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(tierLabel); //empty spacer topCenter.add(spacers.get(2)); //division JLabel divisionLabel = new JLabel(this.division); divisionLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 13)); //custom font divisionLabel.setForeground(new Color(219, 219, 219)); //text color divisionLabel.setAlignmentX(Component.LEFT_ALIGNMENT); topCenter.add(divisionLabel); //bottom center panel JPanel bottomCenter = new JPanel(); bottomCenter.setOpaque(false); bottomCenter.setLayout(new BoxLayout(bottomCenter, BoxLayout.X_AXIS)); //empty spacer bottomCenter.add(spacers.get(3)); //season JLabel winsLabel = new JLabel(this.season); winsLabel.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 14)); //custom font winsLabel.setForeground(new Color(219, 219, 219)); //text color winsLabel.setAlignmentX(Component.LEFT_ALIGNMENT); bottomCenter.add(winsLabel); rightCenter.add(topCenter); rightCenter.add(bottomCenter); centerPanel.add(rightCenter); headerPanel.add(centerPanel, BorderLayout.CENTER); //empty panel to balance right side JPanel ee = new JPanel(); ee.setOpaque(false); ee.setPreferredSize(new Dimension(260, 50)); headerPanel.add(ee, BorderLayout.LINE_END); return headerPanel; }
From source file:LayeredPaneDemo3.java
public LayeredPaneDemo3() { super("Custom MDI: Part IV"); setSize(570, 400);/*from w w w. j av a 2s . c om*/ getContentPane().setBackground(new Color(244, 232, 152)); setLayeredPane(new MDIPane()); ImageIcon ii = new ImageIcon("earth.jpg"); InnerFrame[] frames = new InnerFrame[5]; for (int i = 0; i < 5; i++) { frames[i] = new InnerFrame("InnerFrame " + i); frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200); frames[i].getContentPane().add(new JScrollPane(new JLabel(ii))); getLayeredPane().add(frames[i]); } WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; Dimension dim = getToolkit().getScreenSize(); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); ImageIcon image = new ImageIcon("spiral.gif"); setIconImage(image.getImage()); addWindowListener(l); setVisible(true); }
From source file:edu.ku.brc.ui.IconManager.java
/** * Gets a scaled icon and if it doesn't exist it creates one and scales it * @param icon image to be scaled//from w w w.jav a2 s .c om * @param iconSize the icon size (Std) * @param scaledIconSize the new scaled size in pixels * @return the scaled icon */ public Image getFastScale(final ImageIcon icon, final IconSize iconSize, final IconSize scaledIconSize) { if (icon != null) { int width = scaledIconSize.size(); int height = scaledIconSize.size(); if ((width < 0) || (height < 0)) { //image is nonstd, revert to original size width = icon.getIconWidth(); height = icon.getIconHeight(); } Image imgMemory = createImage(icon.getImage().getSource()); //make sure all pixels in the image were loaded imgMemory = new ImageIcon(imgMemory).getImage(); BufferedImage thumbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(imgMemory, 0, 0, width, height, null); graphics2D.dispose(); imgMemory = thumbImage; return imgMemory; } //else log.error("Couldn't find icon [" + iconSize + "] to scale to [" + scaledIconSize + "]"); return null; }
From source file:edu.ku.brc.specify.rstools.GoogleEarthExporter.java
/** * Takes an ImageIcon (in memory) and writes it out to a file. * @param icon the image icon//from w w w . j a v a2s. co m * @param output the destination file * @return true on success * @throws IOException */ protected boolean writeImageIconToFile(final ImageIcon icon, final File output) throws IOException { if (icon != null && icon.getIconWidth() > 0 && icon.getIconHeight() > 0 && output != null) { try { BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); if (bimage != null) { Graphics g = bimage.createGraphics(); if (g != null) { g.drawImage(icon.getImage(), 0, 0, null); g.dispose(); ImageIO.write(bimage, "PNG", output); return true; } } } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(GoogleEarthExporter.class, ex); // no need to throw an exception or display it } } return false; }