Example usage for javax.swing ImageIcon getImage

List of usage examples for javax.swing ImageIcon getImage

Introduction

In this page you can find the example usage for javax.swing ImageIcon getImage.

Prototype

@Transient
public Image getImage() 

Source Link

Document

Returns this icon's Image.

Usage

From source file:AppSpringLayout.java

protected ImageIcon scaleBufferedImageWithoutLabel(BufferedImage img) {

    ImageIcon icon = null;
    try {//from  w ww  . j a va  2s.c  o  m
        icon = new ImageIcon(img);
        double width = icon.getIconWidth();
        double height = icon.getIconHeight();
        double labelWidth = 300;
        double labelHight = 300;
        double scaleWidth = width / labelWidth;
        double scaleHeight = height / labelHight;

        if (width >= height) {
            // horizontal image
            double newWidth = width / scaleWidth;
            icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH));
        } else {
            // vertical image
            double newHeight = height / scaleHeight;
            icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH));
        }
    } catch (NullPointerException e) {
        try {
            originalImage = (BufferedImage) ImageIO.read(new File("img/error.png"));
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        e.printStackTrace();
    }

    return icon;
}

From source file:AppSpringLayout.java

protected ImageIcon scaleBufferedImage(BufferedImage img, JLabel label) {

    ImageIcon icon = null;
    try {//from   w  w w  .ja  va2s.c  om
        icon = new ImageIcon(img);
        double width = icon.getIconWidth();
        double height = icon.getIconHeight();
        double labelWidth = label.getWidth();
        double labelHight = label.getHeight();
        double scaleWidth = width / labelWidth;
        double scaleHeight = height / labelHight;

        if (width >= height) {
            // horizontal image
            double newWidth = width / scaleWidth;
            icon = new ImageIcon(icon.getImage().getScaledInstance((int) newWidth, -1, Image.SCALE_SMOOTH));
        } else {
            // vertical image
            double newHeight = height / scaleHeight;
            icon = new ImageIcon(icon.getImage().getScaledInstance(-1, (int) newHeight, Image.SCALE_SMOOTH));
        }
    } catch (NullPointerException e) {
        try {
            originalImage = (BufferedImage) ImageIO.read(new File("img/error.png"));
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        e.printStackTrace();
    }

    return icon;
}

From source file:com.biosis.biosislite.vistas.inventario.MantenimientoBien.java

private void tblbienesMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblbienesMouseReleased
    // TODO add your handling code here:
    if (evt.getClickCount() == 1) {

        int fila = tblbienes.getSelectedRow();
        this.bien = lista.get(fila);

        try {//from w ww  .  ja v a  2 s. co m
            nombreField.setText(BeanUtils.getProperty(bien, "nombre"));
            descripcionField.setText(BeanUtils.getProperty(bien, "descripcion"));
            fotoField.setText(BeanUtils.getProperty(bien, "foto"));
            spnStock.setValue(bien.getStockMinimo());
            spnStockMax.setValue(bien.getStockMaximo());
            txtCodigo.setText(bien.getCodigo());

            ImageIcon fot = new ImageIcon(fotoField.getText());
            //                if (fot.getImage().){
            //                    fot = new ImageIcon("img/no_disponible.png");
            //                }
            Icon icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(),
                    Image.SCALE_DEFAULT));
            fotoLbl.setIcon(icono);

            System.out.println("tamao icon: " + fotoLbl.getIcon().getIconHeight());
            if (fotoLbl.getIcon().getIconHeight() == -1) {
                fot = new ImageIcon("img/no_disponible.png");
                icono = new ImageIcon(fot.getImage().getScaledInstance(fotoLbl.getWidth(), fotoLbl.getHeight(),
                        Image.SCALE_DEFAULT));
                fotoLbl.setIcon(icono);
            }

            //                cmbClase.setSelectedItem(bien.getClase());
            claseField.setText(bien.getClase().getNombre());
            listarCamposMod(bien);
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
            Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}

From source file:coffeshop.PaymentPage.java

private void btnScanBTCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScanBTCActionPerformed
    timeStop = false;/*from   w w w  .j  a  v  a  2s.  c om*/
    btnScanBTC.setEnabled(false);
    btcTimer();
    String btcPay = txtPayAmt.getText();
    BigDecimal USD = new BigDecimal(btcPay);
    BigDecimal USDtoBTC = btcPriceIndex();
    BigDecimal BTCDue = USD.divide(USDtoBTC, 5, BigDecimal.ROUND_HALF_UP);
    USDtoBTC = USDtoBTC.setScale(2, BigDecimal.ROUND_HALF_UP);
    lblUSDtoBTC.setText("USD/BTC = " + USDtoBTC);
    lblBTCDue.setText("BTC Due: " + BTCDue);
    try {
        generateQR(btcPay);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Error generating QR Code");
        ex.printStackTrace();
    }
    try {
        BufferedImage image = ImageIO.read(new File("src/ImageRes/QR.jpg"));
        ImageIcon icon = new ImageIcon(image);
        icon.getImage().flush();
        lblQRC.setIcon(icon);
    } catch (IOException ex) {
        System.out.println(ex.getMessage());
    }

    if (lblQRC.getIcon() == null) {
        lblQRC.setIcon(defaultQR);
        JOptionPane.showMessageDialog(null, "Wrong QR Code. Please try again.", "Wrong QR Code",
                JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:com.t3.model.Token.java

public Icon getIcon(int width, int height) {
    ImageIcon icon = new ImageIcon(ImageManager.getImageAndWait(getImageAssetId()));
    Image image = icon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT);
    return new ImageIcon(image);
}

From source file:edu.ku.brc.specify.BackupAndRestoreApp.java

/**
 * Tries to do the login, if doAutoLogin is set to true it will try without displaying a dialog
 * and if the login fails then it will display the dialog
 * @param userName single signon username (for application)
 * @param password single signon password (for application)
 * @param usrPwdProvider the provider//w  w w. j a v a  2 s .  c om
 * @param engageUPPrefs indicates whether the username and password should be loaded and remembered by local prefs
 * @param doAutoLogin whether to try to automatically log the user in
 * @param doAutoClose whether it should automatically close the window when it is logged in successfully
 * @param useDialog use a Dialog or a Frame
 * @param listener a listener for when it is logged in or fails
 * @param iconName name of icon to use
 * @param title name
 * @param appName name
 * @param appIconName application icon name
 * @param helpContext help context for Help button on dialog
 */
public static DatabaseLoginPanel doLogin(final boolean engageUPPrefs,
        final MasterPasswordProviderIFace usrPwdProvider, final boolean doAutoClose,
        final DatabaseLoginListener listener, final String iconName, final String title, final String appName,
        final String appIconName, final String helpContext) //frame's icon name
{

    ImageIcon icon = IconManager.getIcon("AppIcon", IconManager.IconSize.Std32);
    if (StringUtils.isNotEmpty(appIconName)) {
        ImageIcon imgIcon = IconManager.getIcon(appIconName);
        if (imgIcon != null) {
            icon = imgIcon;
        }
    }

    // else
    class DBListener implements DatabaseLoginListener {
        protected JFrame frame;
        protected DatabaseLoginListener frameDBListener;
        protected boolean doAutoCloseOfListener;

        public DBListener(JFrame frame, DatabaseLoginListener frameDBListener, boolean doAutoCloseOfListener) {
            this.frame = frame;
            this.frameDBListener = frameDBListener;
            this.doAutoCloseOfListener = doAutoCloseOfListener;
        }

        public void loggedIn(final Window window, final String databaseName, final String userNameArg) {
            log.debug("UIHelper.doLogin[DBListener]");
            if (doAutoCloseOfListener) {
                frame.setVisible(false);
            }
            frameDBListener.loggedIn(window, databaseName, userNameArg);
        }

        public void cancelled() {
            frame.setVisible(false);
            frameDBListener.cancelled();
        }
    }
    JFrame.setDefaultLookAndFeelDecorated(false);

    JFrame frame = new JFrame(title);
    DatabaseLoginPanel panel = new DatabaseLoginPanel(null, null, false, usrPwdProvider,
            new DBListener(frame, listener, doAutoClose), false, false, title, appName, iconName, helpContext);

    panel.setAutoClose(doAutoClose);
    panel.setWindow(frame);
    frame.setContentPane(panel);
    frame.setIconImage(icon.getImage());
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    frame.pack();

    UIHelper.centerAndShow(frame);

    return panel;
}

From source file:com.t3.model.Token.java

private Asset createAssetFromIcon(ImageIcon icon) {
    if (icon == null)
        return null;

    // Make sure there is a buffered image for it
    Image image = icon.getImage();
    if (!(image instanceof BufferedImage)) {
        image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT);
        Graphics2D g = ((BufferedImage) image).createGraphics();
        icon.paintIcon(null, g, 0, 0);//w w w. ja  va 2 s  . c o m
    }
    // Create the asset
    Asset asset = null;
    try {
        asset = new Asset(name, ImageUtil.imageToBytes((BufferedImage) image));
        if (!AssetManager.hasAsset(asset))
            AssetManager.putAsset(asset);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return asset;
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.DataImportDialog.java

/**
 * Constructor for Import dialog for xls
 * /*w  w  w.  j a  va 2  s  . c o m*/
 * @param config - the config class for configing an xls import
 * @param doesHaveHeaders
 */
public DataImportDialog(final ConfigureXLS config, boolean doesHaveHeaders) {
    this.config = config;
    this.configXLS = config;
    this.file = config.getFile();
    this.fileName = file.getAbsolutePath().toString();
    this.doesFirstRowHaveHeaders = doesHaveHeaders;
    myDisplayTable = null;
    model = new PreviewTableModel();

    ImageIcon appIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
    if (appIcon != null) {
        setIconImage(appIcon.getImage());
    }
}

From source file:com.proyecto.vista.MantenimientoInventario.java

private void buscarInventario() {
    accion = Controlador.MODIFICAR;// w  w  w.  jav a 2  s  . c  om
    //        cargarCombos();
    //        cantidadField.setEditable(false);

    FormularioUtil.activarComponente(panelDatos, true);
    FormularioUtil.activarComponente(panelDatosB, true);
    FormularioUtil.activarComponente(panelFoto, true);
    //        FormularioUtil.activarComponente(panelOpciones, false);
    //        FormularioUtil.activarComponente(panelGuardar, true);

    //        lblbuscar.setText(txtBuscar.getText());
    List<Inventario> listaB = this.inventarioControlador.buscarXSerie(txtBuscar.getText().toUpperCase());

    this.txtBuscar.setText(null);
    this.txtBuscar.requestFocusInWindow();

    if (listaB.isEmpty()) {
        JOptionPane.showMessageDialog(null, "No se encontr el elemento", "Mensaje del Sistema",
                JOptionPane.ERROR_MESSAGE);
    } else {

        inventarioControlador.setSeleccionado(listaB.get(0));

        //            String serie = inventarioControlador.obtenerUltimaSerie(inventarioControlador.getSeleccionado().getBien().getClase().getCodigo());
        //            System.out.println("ULTIMO: "+ inventarioControlador.obtenerUltimaSerie(inventarioControlador.getSeleccionado().getBien().getClase().getCodigo()));
        //            int numero = Integer.valueOf(serie);
        //            System.out.println("ULTIMO NUMERO: "+ numero);
        nombreField.setText(inventarioControlador.getSeleccionado().getBien().getNombre());

        bienGlobal = inventarioControlador.getSeleccionado().getBien();
        //            descripcionField.setText(inventarioControlador.getSeleccionado().getBien().getDescripcion());
        //            fotoField.setText(inventarioControlador.getSeleccionado().getBien().getFoto());
        ImageIcon fot = new ImageIcon(inventarioControlador.getSeleccionado().getBien().getFoto());
        Icon icono = new ImageIcon(
                fot.getImage().getScaledInstance(lblFoto.getWidth(), lblFoto.getHeight(), Image.SCALE_DEFAULT));
        lblFoto.setIcon(icono);

        listaDetalle.clear();
        listaDetalle
                .addAll(detalleControlador.buscarXBienFull(inventarioControlador.getSeleccionado().getBien()));
        listarCampos();
        //INFO INVENTARIO
        cmbEstado.setSelectedItem(inventarioControlador.getSeleccionado().getEstado());

        cmbPeriodo1.setSelectedItem(inventarioControlador.getSeleccionado().getPeriodo());
        periodo = inventarioControlador.getSeleccionado().getPeriodo();

        //            cmbAmbiente.setSelectedItem(inventarioControlador.getSeleccionado().getAmbiente());
        if (inventarioControlador.getSeleccionado().getAmbiente() != null) {
            ambienteField.setText(inventarioControlador.getSeleccionado().getAmbiente().toString());
        }

        if (inventarioControlador.getSeleccionado().getProveedor() != null) {
            proveedorField.setText(inventarioControlador.getSeleccionado().getProveedor().getNombreProveedor());
            proveedor = inventarioControlador.getSeleccionado().getProveedor();
        }

        facturaField.setText(null);

        if (inventarioControlador.getSeleccionado().getFactura() != null) {
            facturaField.setText(inventarioControlador.getSeleccionado().getFactura().getNumeroFactura());
            factura = inventarioControlador.getSeleccionado().getFactura();
        }

        List<Inventario> conteo = inventarioControlador
                .buscarXBien3(inventarioControlador.getSeleccionado().getBien());
        int contar = conteo.size();

        //            lblStock.setText(String.valueOf(contar));
        //            lblUnidades.setVisible(true);
        if (inventarioControlador.getSeleccionado().getImpresionPendiente() != null) {
            chckImpresion.setSelected(inventarioControlador.getSeleccionado().getImpresionPendiente());
        }

        if (inventarioControlador.getSeleccionado().getPrecio() != null) {
            spnPrecio.setValue(inventarioControlador.getSeleccionado().getPrecio());
        }
        serieField.setText(inventarioControlador.getSeleccionado().getSerie());
        serieField.setEditable(false);
        if (inventarioControlador.getSeleccionado().getFechaIngreso() != null) {
            jDateIngreso.setDate(inventarioControlador.getSeleccionado().getFechaIngreso());
        }
        if (inventarioControlador.getSeleccionado().getCodigoFabrica() != null) {
            codFabField.setText(inventarioControlador.getSeleccionado().getCodigoFabrica());
        }
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.DataImportDialog.java

/**
 * Constructor for Import Dialog for a csv
 * //  ww w .  j  ava2s.co m
 * @param config - the config class for configing a csv import
 * @param defaultDelimChar - default delimiter to be used
 * @param defaultTextQual - default text qualifer to be used
 * @param defaultCharSet - default character set to be used
 * @param defaultEscMode - default escape mode to be used
 * @param doesHaveHeaders - default for whether or not the data file contains headers in the first row.
 * @param useTxtQual
 */
public DataImportDialog(final ConfigureCSV config, char defaultDelimChar, char defaultTextQual,
        Charset defaultCharSet, int defaultEscMode, boolean doesHaveHeaders, boolean useTxtQual) {
    this.config = config;
    this.configCSV = config;
    this.file = config.getFile();
    this.fileName = file.getAbsolutePath().toString();
    this.doesFirstRowHaveHeaders = doesHaveHeaders;
    this.charset = defaultCharSet;
    this.escapeMode = defaultEscMode;
    this.delimChar = defaultDelimChar;
    this.stringQualifierChar = defaultTextQual;
    this.shouldUseTextQualifier = useTxtQual;
    highestColumnCount = 0;
    myDisplayTable = new JTable();
    model = new PreviewTableModel();

    ImageIcon appIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
    if (appIcon != null) {
        setIconImage(appIcon.getImage());
    }
}