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 static ImageIcon scaleImage(ImageIcon i, int x, int y) {
    return new ImageIcon(i.getImage().getScaledInstance(x, y, Image.SCALE_SMOOTH));
}

From source file:Main.java

static ImageIcon makeImageIcon(URL url, JComboBox combo, int row) {
    ImageIcon icon = new ImageIcon(url);
    icon.setImageObserver(new ImageObserver() {
        public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
            if (combo.isShowing() && (infoflags & (FRAMEBITS | ALLBITS)) != 0) {
                if (combo.getSelectedIndex() == row) {
                    combo.repaint();//  www.  ja v  a  2s.  c o m
                }
                BasicComboPopup p = (BasicComboPopup) combo.getAccessibleContext().getAccessibleChild(0);
                JList list = p.getList();
                if (list.isShowing()) {
                    list.repaint(list.getCellBounds(row, row));
                }
            }
            return (infoflags & (ALLBITS | ABORT)) == 0;
        };
    });
    return icon;
}

From source file:Main.java

/**
 * return image icon from resource location ( ie Classpath )
 * File could be placed in the classpath or in a jar file
 * @param aFilename file name of the image file
 * @param aRetrieverClass class request for the image
 * @return image icon//from  w w w  .ja  v a  2 s  . co  m
 */
public final static ImageIcon GetImageFromResource(String aFilename, Class aRetrieverClass) {
    URL url = null;
    url = aRetrieverClass.getResource(aFilename);
    if (url == null)
        return null;
    else
        return new ImageIcon(url);
}

From source file:Main.java

public static void display(BufferedImage image) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JLabel(new ImageIcon(image)));
    f.pack();//from  w  w w.j a  va2 s.c o m
    f.setVisible(true);
}

From source file:ScrollPaneDemo.java

public ScrollPaneDemo() {
    super("JScrollPane Demo");
    ImageIcon ii = new ImageIcon("largeJava2sLogo.jpg");
    JScrollPane jsp = new JScrollPane(new JLabel(ii));
    getContentPane().add(jsp);/*from   ww  w  . ja  v a2s  . co m*/
    setSize(300, 250);
    setVisible(true);
}

From source file:Main.java

/**
 * Creates a static rectangular image with given color, width and height.
 *///from  w w w  .ja v a2  s.  c o  m
public static Icon buildStaticImage(Color color, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            image.setRGB(x, y, color.getRGB());
        }
    }
    return new ImageIcon(image);
}

From source file:Main.java

public Main() {
    ImageIcon aboutIcon = new ImageIcon("about16.gif");
    ImageIcon addIcon = new ImageIcon("add16.gif");
    ImageIcon copyIcon = new ImageIcon("copy16.gif");

    String[] columnNames = { "Picture", "Description" };
    Object[][] data = { { aboutIcon, "About" }, { addIcon, "Add" }, { copyIcon, "Copy" }, };

    DefaultTableModel model = new DefaultTableModel(data, columnNames);
    JTable table = new JTable(model) {
        public Class getColumnClass(int column) {
            return (column == 0) ? Icon.class : Object.class;
        }/*from w w  w  .  j  a  va  2 s .  c o  m*/
    };
    table.setPreferredScrollableViewportSize(table.getPreferredSize());

    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane);
}

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton(new ImageIcon("img/icon.gif"), false);
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);//w  w  w.  j  a va  2  s. c o m

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);
    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);

}

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton(new ImageIcon("img/icon.gif"));
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);/*from   w  ww  . j  a  v  a 2 s.c  o  m*/

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);
    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);

}

From source file:Scale.java

public Scale() {
    super();
    ImageIcon icon = new ImageIcon("java2s.GIF");
    image = icon.getImage();
}