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:Main.java

@Override
public void mouseClicked(MouseEvent e) {
    ImageIcon img = new ImageIcon("yourImage.png");
    //place image in your working directory
    addImage(img.getImage());/*from   w w  w  . j a  v  a 2s .  c om*/
}

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

public SacomutDevice(String name) {
    super(name);//from w  w w .  j a v  a 2 s .  co m
    this.setCpuSpeed(350);
    this.setTotalMemory(1024);
    this.setDeviceType(DeviceType.SACOMUT);
    this.setDeviceName(name);
    try {
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/sacomut.jpg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Main.java

public Main() {
    super("JLayeredPane Demo");
    setSize(256, 256);//from  ww  w  .  ja  va  2s .c om

    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.setOpaque(false);

    JLabel label1 = new JLabel("Username:");
    label1.setForeground(Color.white);
    content.add(label1);

    JTextField field = new JTextField(15);
    content.add(field);

    JLabel label2 = new JLabel("Password:");
    label2.setForeground(Color.white);
    content.add(label2);

    JPasswordField fieldPass = new JPasswordField(15);
    content.add(fieldPass);

    setLayout(new FlowLayout());
    add(content);
    ((JPanel) getContentPane()).setOpaque(false);

    ImageIcon earth = new ImageIcon("largeJava2sLogo.png");
    JLabel backlabel = new JLabel(earth);
    getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE));
    backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight());
    super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:ThumbnailTools.java

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

From source file:muh.avagadroYasasi.java

/**
 * Creates new form kutle/*from ww  w . j a v  a  2s .co  m*/
 */
public avagadroYasasi() {
    initComponents();
    ImageIcon ikon0 = new ImageIcon("C:\\\\Users\\\\serenn\\\\Desktop\\\\images\\cancel-icon.png");
    jButton2.setIcon(ikon0);

    ImageIcon ikon1 = new ImageIcon("C:\\\\Users\\\\serenn\\\\Desktop\\\\images\\Button-Help-icon.png");
    jButton1.setIcon(ikon1);

}

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

public HTACoordDevice(String name) {
    super(name);/*www  . j a v  a  2 s .c  o  m*/
    this.setCpuSpeed(500);
    this.setTotalMemory(16000);
    this.setDeviceType(DeviceType.HTA_COORD);
    this.setDeviceName(name);
    try {
        byte[] imageInByte;
        imageInByte = IOUtils
                .toByteArray(getClass().getClassLoader().getResourceAsStream("image/htaCoord.jpg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.isencia.passerelle.hmi.action.ModelResumer.java

public ModelResumer(final HMIBase base) {
    super(base, HMIMessages.getString(HMIMessages.MENU_RESUME),
            new ImageIcon(HMIBase.class.getResource("resources/resume.gif")));
}

From source file:StocksTable5.java

public StocksTable5() {
    super("Stocks Table");
    setSize(600, 300);//  w ww . j av  a 2 s.  c o  m

    m_data = new StockTableData();

    m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT);
    m_title.setFont(new Font("TimesRoman", Font.BOLD, 24));
    m_title.setForeground(Color.black);
    getContentPane().add(m_title, BorderLayout.NORTH);

    m_table = new JTable();
    m_table.setAutoCreateColumnsFromModel(false);
    m_table.setModel(m_data);

    for (int k = 0; k < StockTableData.m_columns.length; k++) {
        DefaultTableCellRenderer renderer = new ColoredTableCellRenderer();
        renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment);
        TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null);
        m_table.addColumn(column);
    }

    JTableHeader header = m_table.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(m_data.new ColumnListener(m_table));
    header.setReorderingAllowed(true);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(m_table);
    getContentPane().add(ps, BorderLayout.CENTER);

    JMenuBar menuBar = createMenuBar();
    setJMenuBar(menuBar);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:jmap2gml.ItemImage.java

private static HashMap<String, Image> readConfig() {
    HashMap<String, Image> out = new HashMap<>();
    JSONTEXT = "";
    Image img;//ww  w  .  j a  va  2 s . c om

    Scanner scan;
    try {
        scan = new Scanner(new File("ImageItemConfig"));

        while (scan.hasNext()) {
            JSONTEXT += scan.nextLine();
        }

        config = new JSONObject(JSONTEXT);

        for (String str : config.keySet()) {
            if (!str.contains("XOFFSET") && !str.contains("YOFFSET")) {
                img = (new ImageIcon(config.getString(str))).getImage();
                out.put(str, img);
            }
        }
    } catch (Exception ex) {
        Logger.getLogger(ItemImage.class.getName()).log(Level.SEVERE, null, ex);
    }

    return out;
}

From source file:de.tor.tribes.ui.renderer.TendencyTableCellRenderer.java

public TendencyTableCellRenderer() {
    yellow = new ImageIcon(TendencyTableCellRenderer.class.getResource("/res/ui/yellow_arrow_horizontal.png"));
    red = new ImageIcon(TendencyTableCellRenderer.class.getResource("/res/ui/red_arrow_up.png"));
    green = new ImageIcon(TendencyTableCellRenderer.class.getResource("/res/ui/green_arrow_down.png"));
}