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:com.biosis.biosislite.vistas.inventario.MantenimientoFactura.java

public MantenimientoFactura() {
    initComponents();//from  w w  w  .  j a  va  2s .c o  m
    listar();

    ImageIcon fot = new ImageIcon("img/no_disponible.png");
    Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblFactura.getWidth(), lblFactura.getHeight(),
            Image.SCALE_DEFAULT));
    lblFactura.setIcon(icono);

    FormularioUtil.activarComponente(panelDatos, false);
    FormularioUtil.activarComponente(panelOpciones, true);
    FormularioUtil.activarComponente(panelGuardar, false);
}

From source file:com.akman.excel.view.frmSelectImage.java

private void btnSelectImageActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnSelectImageActionPerformed
{//GEN-HEADEREND:event_btnSelectImageActionPerformed
    JFileChooser chooser = new JFileChooser();

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Image files", "jpg", "png", "gif", "bmp");
    chooser.setFileFilter(filter);//  ww w.  jav  a2s.c  o  m

    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogTitle("Select The Image");
    chooser.setMultiSelectionEnabled(false);
    int res = chooser.showOpenDialog(null);
    if (res == JFileChooser.APPROVE_OPTION) {

        //Saving file inside the file
        File file = chooser.getSelectedFile();

        //        if(!file.equals(filter))
        //        {
        //        JOptionPane.showMessageDialog(null, "Wrong File Selected","ERROR",JOptionPane.ERROR_MESSAGE);
        //        return;
        //        }

        //System.out.println(file.getAbsolutePath());
        ImageIcon image = new ImageIcon(file.getAbsolutePath());

        fileName = file.getAbsolutePath();

        // Get Width And Height of PicLabel
        Rectangle rect = lblImage.getBounds();

        //System.out.println(lblImage.getBounds());
        //Scaling the image to fit in the picLabel
        Image scaledimage = image.getImage().getScaledInstance(rect.width, rect.height, Image.SCALE_DEFAULT);
        //converting the image back to image icon to make an acceptable picLabel
        image = new ImageIcon(scaledimage);

        lblImage.setIcon(image);

        txtPath.setText(fileName);

        try {

            File images = new File(fileName);

            FileInputStream fis = new FileInputStream(images);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();

            byte[] buf = new byte[1024];

            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);
            }

            person_image = bos.toByteArray();

        } catch (Exception e) {

            JOptionPane.showMessageDialog(null, e);
        }

    }
}

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

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    JFileChooser fc = new JFileChooser();
    int respuesta = fc.showOpenDialog(this);
    if (respuesta == JFileChooser.APPROVE_OPTION) {
        File archivoElegido = fc.getSelectedFile();
        facturaField.setText(archivoElegido.getAbsolutePath());

        //            fotolbl.setIcon(new ImageIcon("C:/Users/Documentos/Desktop/HS/" + fotosField.getText()));
        ImageIcon fot = new ImageIcon(facturaField.getText());
        Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblFactura.getWidth(),
                lblFactura.getHeight(), Image.SCALE_DEFAULT));
        lblFactura.setIcon(icono);//from w  w  w.  ja  v  a2  s. c o  m

    }
}

From source file:com.google.code.facebook.graph.sna.applet.GraphZoomScrollPaneDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./*  w w w .  j av a 2  s  .c o m*/
 * 
 */
public GraphZoomScrollPaneDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<String, Number>();
    String[] v = createVertices(10);
    createEdges(v);

    ImageIcon sandstoneIcon = null;
    String imageLocation = "/images/Sandstone.jpg";
    try {
        sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = sandstoneIcon;
    vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "GraphZoomScrollPane Demo";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 30);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

    vv.addGraphMouseListener(new TestGraphMouseListener<String>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    vv.setForeground(Color.lightGray);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:edu.ku.brc.ui.ImageDisplay.java

/**
 * @param newImageIcon//from w  w  w . j  a v a2 s.co m
 */
public void setImage(final ImageIcon newImageIcon) {
    if (newImageIcon != null) {
        setImage(newImageIcon.getImage());
    } else {
        setImage((Image) null);
    }
    notifyOnUIThread(true, true);
    //invalidate();
    //doLayout();
}

From source file:edu.uci.ics.jung.samples.GraphZoomScrollPaneDemo.java

/**
 * create an instance of a simple graph with controls to
 * demo the zoom features./* ww  w  .  j a  va 2  s  . c om*/
 * 
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public GraphZoomScrollPaneDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<String, Number>();
    String[] v = createVertices(10);
    createEdges(v);

    ImageIcon sandstoneIcon = null;
    String imageLocation = "/images/Sandstone.jpg";
    try {
        sandstoneIcon = new ImageIcon(getClass().getResource(imageLocation));
    } catch (Exception ex) {
        System.err.println("Can't load \"" + imageLocation + "\"");
    }
    final ImageIcon icon = sandstoneIcon;
    vv = new VisualizationViewer<String, Number>(new KKLayout<String, Number>(graph));

    if (icon != null) {
        vv.addPreRenderPaintable(new VisualizationViewer.Paintable() {
            public void paint(Graphics g) {
                Dimension d = vv.getSize();
                g.drawImage(icon.getImage(), 0, 0, d.width, d.height, vv);
            }

            public boolean useTransform() {
                return false;
            }
        });
    }
    vv.addPostRenderPaintable(new VisualizationViewer.Paintable() {
        int x;
        int y;
        Font font;
        FontMetrics metrics;
        int swidth;
        int sheight;
        String str = "GraphZoomScrollPane Demo";

        public void paint(Graphics g) {
            Dimension d = vv.getSize();
            if (font == null) {
                font = new Font(g.getFont().getName(), Font.BOLD, 30);
                metrics = g.getFontMetrics(font);
                swidth = metrics.stringWidth(str);
                sheight = metrics.getMaxAscent() + metrics.getMaxDescent();
                x = (d.width - swidth) / 2;
                y = (int) (d.height - sheight * 1.5);
            }
            g.setFont(font);
            Color oldColor = g.getColor();
            g.setColor(Color.lightGray);
            g.drawString(str, x, y);
            g.setColor(oldColor);
        }

        public boolean useTransform() {
            return false;
        }
    });

    vv.addGraphMouseListener(new TestGraphMouseListener<String>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray));
    vv.getRenderContext().setArrowDrawPaintTransformer(new ConstantTransformer(Color.lightGray));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<String>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {
        public String transform(Number edge) {
            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);
    vv.setForeground(Color.lightGray);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<String, Number>();
    vv.setGraphMouse(graphMouse);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JButton reset = new JButton("reset");
    reset.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity();
            vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity();
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(reset);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:edu.ku.brc.ui.ChooseFromListDlg.java

/**
 * Constructor.//from   w  w w  .  ja  v a2s  . c o  m
 * 
 * @param frame parent frame
 * @param title the title of the dialog
 * @param desc
 * @param itemList the list to be selected from
 * @param whichBtns mask describing which buttons to create
 * @param helpContext  help context identifier
 * @throws HeadlessException
 */
public ChooseFromListDlg(final Frame frame, final String title, final String desc, final int whichBtns,
        final List<T> itemList, final String helpContext) throws HeadlessException {
    super(frame, true);

    this.title = title;
    this.desc = desc;
    this.items = itemList;
    this.whichBtns = whichBtns;
    this.helpContext = helpContext;

    setLocationRelativeTo(frame);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

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

From source file:edu.ku.brc.ui.ChooseFromListDlg.java

/**
 * Constructor.//from  w  ww  .  java  2  s .com
 * 
 * @param dlg parent frame
 * @param title the title of the dialog
 * @param desc
 * @param itemList the list to be selected from
 * @param whichBtns mask describing which buttons to create
 * @param helpContext  help context identifier
 * @throws HeadlessException
 */
public ChooseFromListDlg(final Dialog dlg, final String title, final String desc, final int whichBtns,
        final List<T> itemList, final String helpContext) throws HeadlessException {
    super(dlg, true);

    this.title = title;
    this.desc = desc;
    this.items = itemList;
    this.whichBtns = whichBtns;
    this.helpContext = helpContext;

    setLocationRelativeTo(dlg);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

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

From source file:gestionelectrica.VentanaEjemploGraf.java

private void rellenar(JPanel jp) {
    // Create a simple XY chart
    XYSeries series = new XYSeries("EC");
    series.add(1, 1);/*from  w  w  w.  j  av  a 2 s.c om*/
    series.add(1, 2);
    series.add(2, 1);
    series.add(3, 9);
    series.add(4, 10);
    series.add(7, 15);
    series.add(10, 6);
    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Energa comprada", // Title
            "hora", // x-axis Label
            "KWh", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    JFreeChart pieChart = ChartFactory.createXYLineChart("EJEMPLOOOO", "Category", "Score", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    System.out.println(System.getProperty("user.home"));
    System.out.println(System.getProperty("java.io.tmpdir"));
    System.out.println(System.getProperties());
    File f = new File(System.getProperty("java.io.tmpdir") + "\\chart.jpg");
    try {
        ChartUtilities.saveChartAsJPEG(f, chart, jp.getWidth(), jp.getHeight());
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
        System.err.println(e.getMessage());
    }
    // Adding chart into a chart panel
    //ChartPanel chartPanel = new ChartPanel(pieChart);

    // settind default size
    //chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    // add to contentPane
    //setContentPane(chartPanel);
    //jPanel1.add(chartPanel);
    ImageIcon ic = new ImageIcon(f.getAbsolutePath());
    ImagePanel panel = new ImagePanel(ic.getImage(), jp.getWidth(), jp.getHeight());
    jp.add(panel);
    /*jPanel1.repaint();
    jPanel1.updateUI();
    jPanel1.validate();*/

    if (f.delete())
        System.out.println("BORRADO CORRECTAMENTE");
    else
        System.err.println("NO SE PUDO BORRAR");
}

From source file:agendapoo.View.FrmMinhaAtividade.java

private void setFrameIcon() {
    ImageIcon icon = new ImageIcon("src//agendapoo//imgs//file_edit.png");
    this.setIconImage(icon.getImage());
}