Example usage for javax.swing ImageIcon ImageIcon

List of usage examples for javax.swing ImageIcon ImageIcon

Introduction

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

Prototype

public ImageIcon(byte[] imageData) 

Source Link

Document

Creates an ImageIcon from an array of bytes which were read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.

Usage

From source file:ThumbnailTools.java

/**
 * Create a thumbnail for the current image
 * @param size the size//from   w w  w  .  ja  v a 2 s .  co m
 * @param dir the direction, Horizontal or Vertical
 * @param scale the scale
 * @return the thumbnail image
 */
public Image getThumbnail(int size, int dir, int scale) {
    if (dir == HORIZONTAL) {
        thumb = new ImageIcon(image.getImage().getScaledInstance(size, -1, scale));
    } else {
        thumb = new ImageIcon(image.getImage().getScaledInstance(-1, size, scale));
    }
    return thumb.getImage();
}

From source file:Main.java

public void drawImage() {
    Graphics2D g = img.createGraphics();
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHints(hints);//  w w w.java  2s  . c  o  m

    g.setStroke(new BasicStroke(4));
    for (Ellipse2D shape : shapes) {
        g.setColor(Color.blue);
        g.fill(shape);
        if (shape.contains(mouse)) {
            g.setColor(Color.RED);
        } else {
            g.setColor(Color.YELLOW);
        }
        g.draw(shape);
    }

    l.setIcon(new ImageIcon(img));

    g.dispose();
}

From source file:co.edu.eam.ingesoft.desarrollo.vista.gui.ReportesEstadisticas.java

/**
 * Creates new form ReportesEstadisticas
 *///from  www . ja va2  s  . c om
public ReportesEstadisticas() {
    initComponents();
    this.setTitle("Reportes y Estadisticas");
    this.setLocationRelativeTo(null);
    this.setResizable(false);
    this.setIconImage(new ImageIcon(getClass().getResource("/imagenes/icono.png")).getImage());
    controlador = new ControladorVentanaReportesyEstadisticas();
    cargarEmpresas();
}

From source file:org.jdal.beans.IconPropertyEditor.java

/**
 * Load image from classpath /* www. j a v  a  2  s  . c o  m*/
 * @param text the classpath of image resource
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 */
@Override
public void setAsText(String text) throws IllegalArgumentException {
    Resource resource = new ClassPathResource(text);
    Icon icon = null;
    try {
        Image image = Toolkit.getDefaultToolkit().getImage(resource.getURL());
        icon = new ImageIcon(image);
    } catch (IOException e) {
        log.error(e);
    }
    setValue(icon);
}

From source file:com.imag.nespros.network.devices.AMIDevice.java

public AMIDevice(String name) {
    super(name);/*from   w w w.j av  a2  s  . c o  m*/
    this.setCpuSpeed(10);
    this.setTotalMemory(128);
    this.setDeviceType(DeviceType.AMI);
    this.setDeviceName(name);
    //String imageURI = getClass().getClassLoader().getResource("image"+File.separator+"meter.jpeg").getFile();
    //icon = new MyLayeredIcon(new ImageIcon("icons"+File.separator+"meter.jpeg").getImage());
    // icon = new MyLayeredIcon(new ImageIcon(imageURI).getImage());
    try {
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/meter.jpeg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:agendapoo.View.FrmCadastroAtividade.java

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

From source file:JTextPaneDemo.java

public JTextPaneDemo() {
    super("JTextPane Demo");

    JScrollPane scrollPane = new JScrollPane(textPane);
    getContentPane().add(scrollPane, BorderLayout.CENTER);

    setEndSelection();/*from   w  ww . j  av  a 2 s.  c o  m*/
    textPane.insertIcon(new ImageIcon("java2sLogo.GIF"));
    insertText("\nWebsite for: www.java2s.com \n\n", BOLD_BLACK);

    setEndSelection();
    insertText("                                    ", BLACK);
    setEndSelection();
    insertText("\n      Java            " + "                                    " + "Source\n\n", ITALIC_GRAY);

    insertText(" and Support. \n", BLACK);

    setEndSelection();
    JButton manningButton = new JButton("Load the web site for www.java2s.com");
    manningButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textPane.setEditable(false);
            try {
                textPane.setPage("http://www.java2s.com");
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    });
    textPane.insertComponent(manningButton);

    setSize(500, 450);
    setVisible(true);
}

From source file:ImageViewer.java

public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == openItem) {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("."));

        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory();
            }//from  w  ww .j ava2s  .c o  m

            public String getDescription() {
                return "GIF Images";
            }
        });

        int r = chooser.showOpenDialog(this);
        if (r == JFileChooser.APPROVE_OPTION) {
            String name = chooser.getSelectedFile().getName();
            label.setIcon(new ImageIcon(name));
        }
    } else if (source == exitItem)
        System.exit(0);
}

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

public void getImage() {
    try {/*from   w  w  w .j  av  a  2 s .c o  m*/
        Connection conn = null;
        conn = Javaconnect.ConnecrDb();

        String sql = "SELECT Image FROM ExcelData where Id = 1";

        pst = conn.prepareStatement(sql);

        rs = pst.executeQuery();

        if (rs.next()) {
            byte[] imagedata = rs.getBytes("Image");
            format = new ImageIcon(imagedata);
            Rectangle rect = lblImage.getBounds();
            //Scaling the image to fit in the picLabel
            Image scaledimage = format.getImage().getScaledInstance(rect.width, rect.height,
                    Image.SCALE_DEFAULT);
            //converting the image back to image icon to make an acceptable picLabel
            format = new ImageIcon(scaledimage);

            lblImage.setIcon(format);
        }

    } catch (SQLException ex) {
        Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(pst);
        Connection conn = null;
        DbUtils.closeQuietly(conn);
    }
}

From source file:freemrs.ChartPanelDraw.java

public ChartPanelDraw(java.util.List<Vitals> result, String type) {
    this.type = type;
    this.result = result;
    dataset = createTimeDataset();/*from  w  w w . j  a  v a  2s  .  c  o m*/
    chartPanel = createChart(dataset, type);

    JFrame f = new JFrame("Vital Plot"); //Jframe to draw the graph
    f.setTitle("Vital Plot");
    f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    f.setLayout(new BorderLayout(0, 5));
    f.add(chartPanel, BorderLayout.CENTER);
    f.setIconImage(new ImageIcon(getClass().getResource("/images/icon_transparent.png")).getImage());

    chartPanel.setHorizontalAxisTrace(true); //set properties of the graph 
    chartPanel.setVerticalAxisTrace(true);
    chartPanel.setMouseWheelEnabled(true);

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(createTrace()); //Add components to panel
    panel.add(createDate());
    panel.add(createZoom());
    f.add(panel, BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}