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

public Main() {
    Vector model = new Vector();
    model.addElement(new Item(new ImageIcon("copy16.gif"), "copy"));
    model.addElement(new Item(new ImageIcon("add16.gif"), "add"));
    model.addElement(new Item(new ImageIcon("about16.gif"), "about"));

    JComboBox comboBox;//from   w w w .ja  va 2s.  c o m

    comboBox = new JComboBox(model);
    comboBox.setRenderer(new ItemRenderer());
    getContentPane().add(comboBox, BorderLayout.SOUTH);
}

From source file:Main.java

public Main() {
    JPanel simplePanel = new JPanel(new GridLayout(7, 1, 5, 5));
    ImageIcon icon = new ImageIcon(Toolkit.getDefaultToolkit().getImage("matte.gif"));
    simplePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red),
            BorderFactory.createMatteBorder(-1, -1, -1, -1, icon)));
    simplePanel.add(new JLabel("Examples"), JLabel.CENTER);

    add(simplePanel);/*w  w  w  . ja v  a2  s .co m*/
}

From source file:ImageUtil.java

/**
 * get image orientation type/*  ww  w  .  j  a va2 s.  co m*/
 * @param imageFile
 * @return 0:Landscape, 1:Portrait
 */
public static int getOrientation(File imageFile) {
    int result = 0;
    ImageIcon image = new ImageIcon(imageFile.getPath());
    if (image.getIconWidth() > image.getIconHeight()) {
        result = 0;
    } else {
        result = 1;
    }
    image = null;
    return result;
}

From source file:Main.java

/** Constructs a JButton with an icon from the given file id. */
public static JButton makeButton(final Object owner, final String id, final String altText, final int wpad,
        final int hpad) {
    final URL url = owner.getClass().getResource(id);
    ImageIcon icon = null;/*from w ww  . j a va  2 s.c o m*/
    if (url != null)
        icon = new ImageIcon(url);
    JButton button;
    if (icon == null)
        button = new JButton(altText);
    else {
        button = new JButton(icon);
        button.setPreferredSize(new Dimension(icon.getIconWidth() + wpad, icon.getIconHeight() + hpad));
    }
    return button;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    JTextField tf = new JTextField(5);
    JLabel label = new JLabel(new ImageIcon("Test.gif"));
    label.setOpaque(true);//from   ww w  . j  av a  2  s  .  c o m
    label.setBackground(tf.getBackground());
    label.setPreferredSize(new Dimension(label.getPreferredSize().width, tf.getPreferredSize().height));
    p.setBorder(tf.getBorder());
    tf.setBorder(null);
    p.add(label, BorderLayout.WEST);
    p.add(tf, BorderLayout.CENTER);
    JPanel p1 = new JPanel();
    p1.add(p);
    getContentPane().add(p1);
    pack();
    setLocationRelativeTo(null);
}

From source file:Main.java

/**
 * Returns an ImageIcon, or throws a RuntimeException if the path was
 * invalid./*w  ww . j  ava 2 s.  c  om*/
 * @param clazz  The class to "baseline" the path off of.
 * @param path  The path from the location of the "baseline" class (clazz).
 * @return  An ImageIcon object.
 */
public static ImageIcon createImageIcon(Class clazz, String path) {
    URL imageUrl = clazz.getResource(path);

    if (imageUrl != null) {
        return new ImageIcon(imageUrl);
    }

    throw new RuntimeException("Couldn't find file: " + path);
}

From source file:Main.java

public Main() {
    super("Grab and drag Demo");
    ImageIcon ii = new ImageIcon("largeJava2sLogo.jpg");
    JScrollPane jsp = new JScrollPane(new GrabAndScrollLabel(ii));
    getContentPane().add(jsp);/*from w ww.jav a  2  s .c om*/
    setSize(300, 250);
    setVisible(true);

    super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

/** Constructs a JToggleButton with an icon from the given file id. */
public static JToggleButton makeToggleButton(final Object owner, final String id, final String altText,
        final int wpad, final int hpad) {
    final URL url = owner.getClass().getResource(id);
    ImageIcon icon = null;//from   w ww. j ava2  s.  c o  m
    if (url != null)
        icon = new ImageIcon(url);
    JToggleButton button;
    if (icon == null)
        button = new JToggleButton(altText);
    else {
        button = new JToggleButton(icon);
        button.setPreferredSize(new Dimension(icon.getIconWidth() + wpad, icon.getIconHeight() + hpad));
    }
    return button;
}

From source file:ImageUtil.java

/**
 * Returns an ImageIcon, or null if the path was invalid.
 *//*from w  ww.  j ava  2  s .com*/
public static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = ImageUtil.class.getResource(path);
    if (imgURL != null) {
        return new ImageIcon(imgURL);
    } else {
        System.err.println("Couldn't find file: " + path);
        return null;
    }
}

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(200, 50));
    JButton jb = new JButton(new ImageIcon("bullet.gif"));
    p.add(jb);//from  w  ww  .  j a va  2 s  .c om

    getContentPane().add(p);

    pack();
    setVisible(true);
}