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:vista.ReporteConversionLeads.java

/**
 * Creates new form ReporteConversionLeads
 *//*from   w w w .j a  v a2 s.c om*/
public ReporteConversionLeads() {
    initComponents();
    setIconImage(new ImageIcon(getClass().getResource("/recursos/logoTT.png")).getImage());
}

From source file:Main.java

public Main() {
    super("JSpinner Icon Test");
    setSize(300, 80);//from w w w.j a va  2 s  . co  m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"),
            new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") };
    JSpinner s1 = new JSpinner(new SpinnerListModel(nums));
    s1.setEditor(new IconEditor(s1));
    c.add(new JLabel(" Icon Spinner"));
    c.add(s1);

    setVisible(true);
}

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

public ModelSuspender(final HMIBase base) {
    super(base, HMIMessages.getString(HMIMessages.MENU_SUSPEND),
            new ImageIcon(HMIBase.class.getResource("resources/suspend.gif")));
}

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

public PADevice(String name) {
    super(name);/*from   w  w  w. j  a v a 2 s . com*/
    this.setCpuSpeed(1);
    this.setTotalMemory(5);
    this.setDeviceType(DeviceType.PA);
    this.setDeviceName(name);

    try {
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/pa.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() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Action [" + e.getActionCommand() + "] performed!\n");
        }//from w w  w.j av a  2  s .c  o  m
    };
    JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    justifyMenu.add(leftJustify);
    justifyMenu.add(rightJustify);
    justifyMenu.add(centerJustify);
    justifyMenu.add(fullJustify);

    menuBar.add(justifyMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

}

From source file:IconSpinner.java

public IconSpinner() {
    super("JSpinner Icon Test");
    setSize(300, 80);//from  w w  w. j  a  v  a 2 s .  c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();
    c.setLayout(new GridLayout(0, 2));

    Icon nums[] = new Icon[] { new ImageIcon("1.gif"), new ImageIcon("2.gif"), new ImageIcon("3.gif"),
            new ImageIcon("4.gif"), new ImageIcon("5.gif"), new ImageIcon("6.gif") };
    JSpinner s1 = new JSpinner(new SpinnerListModel(nums));
    s1.setEditor(new IconEditor(s1));
    c.add(new JLabel(" Icon Spinner"));
    c.add(s1);

    setVisible(true);
}

From source file:Main.java

License:asdf

public void paint(Graphics g, JComponent c) {
    FontMetrics metrics = c.getFontMetrics(g.getFont());
    g.setColor(c.getForeground());/*from   ww  w .ja  v a 2  s  .  c  om*/
    g.drawString(((JToolTip) c).getTipText(), 1, 1);
    g.drawImage(new ImageIcon("yourImage").getImage(), 1, metrics.getHeight(), c);
}

From source file:MenuExample.java

public MenuExample() {
    menuBar = new JMenuBar();
    JMenu formatMenu = new JMenu("Justify");
    formatMenu.setMnemonic('J');

    MenuAction leftJustifyAction = new MenuAction("Left", new ImageIcon("1.gif"));
    MenuAction rightJustifyAction = new MenuAction("Right", new ImageIcon("2.gif"));
    MenuAction centerJustifyAction = new MenuAction("Center", new ImageIcon("3.gif"));
    MenuAction fullJustifyAction = new MenuAction("Full", new ImageIcon("4.gif"));

    JMenuItem item;//www.  java 2s. c  o m
    item = formatMenu.add(leftJustifyAction);
    item.setMnemonic('L');
    item = formatMenu.add(rightJustifyAction);
    item.setMnemonic('R');
    item = formatMenu.add(centerJustifyAction);
    item.setMnemonic('C');
    item = formatMenu.add(fullJustifyAction);
    item.setMnemonic('F');

    menuBar.add(formatMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

}

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

public DCDevice(String name) {
    super(name);/*  ww w  . j  av a 2 s .c o  m*/
    this.setCpuSpeed(100);
    this.setTotalMemory(512);
    this.setDeviceType(DeviceType.DC);
    this.setDeviceName(name);

    try {
        byte[] imageInByte;
        imageInByte = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("image/dc.jpeg"));
        icon = new MyLayeredIcon(new ImageIcon(imageInByte).getImage());
    } catch (IOException ex) {
        Logger.getLogger(AMIDevice.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:StocksTable4.java

public StocksTable4() {
    super("Stocks Table");
    setSize(600, 300);/*ww w.j a v a 2 s. co  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);

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