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() {
    JRadioButton radMarriedYes = new JRadioButton("Yes", 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);//from   www. j  a  va 2 s .  com

    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("Yes", 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);//w ww  .  j ava2s .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:PngIcon.java

public PngIcon() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton bt = new JButton(new ImageIcon("dtmail.png"));
    JLabel lab = new JLabel(new ImageIcon("dtterm.png"));
    bt.setFocusPainted(false);//  www. j  av a2 s  .  c  o m

    frame.add(bt, BorderLayout.NORTH);
    frame.add(lab, BorderLayout.SOUTH);
    frame.setBounds(50, 50, 200, 200);
    frame.setVisible(true);
}

From source file:GrayImage.java

public void paint(Graphics g) {
    Image myImage = new ImageIcon("yourImage.png").getImage();
    BufferedImage bufferedImage = new BufferedImage(myImage.getHeight(this), myImage.getWidth(this),
            BufferedImage.TYPE_BYTE_GRAY);

    Graphics gi = bufferedImage.getGraphics();
    gi.drawImage(myImage, 0, 0, null);//  w ww. j av a  2s  .  co  m
    gi.dispose();

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(bufferedImage, null, 0, 0);
}

From source file:Crop.java

public Crop() {
    super();/*from   w w w. j  a va 2  s. c o m*/
    ImageIcon icon = new ImageIcon("java2s.PNG");
    image = icon.getImage();
    image = createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(73, 63, 141, 131)));
}

From source file:MainClass.java

MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton jb = new JButton("Ok", new ImageIcon("bullet.gif"));
    jb.setHorizontalAlignment(SwingConstants.LEFT);
    jb.setMnemonic('O');

    getContentPane().add(jb, BorderLayout.CENTER);

    jb = new JButton("<html><i>Cancel</i></html>");
    jb.setVerticalAlignment(SwingConstants.BOTTOM);

    jb.setDefaultCapable(true);/* ww w.  ja  v  a  2  s. co  m*/

    getContentPane().add(jb, BorderLayout.EAST);

    getRootPane().setDefaultButton(jb);

    setSize(200, 100);
    setVisible(true);
}

From source file:ImageFlip.java

public void paint(Graphics g) {
    Image myImage = new ImageIcon("yourImage.jpg").getImage();
    BufferedImage bufferedImage = new BufferedImage(myImage.getWidth(null), myImage.getHeight(null),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) g;

    Graphics gb = bufferedImage.getGraphics();
    gb.drawImage(myImage, 0, 0, null);//from   w  w  w. ja  va 2  s  . com
    gb.dispose();

    AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
    tx.translate(-myImage.getWidth(null), 0);
    AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    bufferedImage = op.filter(bufferedImage, null);

    g2d.drawImage(myImage, 10, 10, null);
    g2d.drawImage(bufferedImage, null, 300, 10);
}

From source file:Main.java

public Main() throws HeadlessException {
    setSize(300, 300);//from  w w  w.  j  a v a2s  .c o  m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    Icon icon = new ImageIcon("a.png");
    JLabel label1 = new JLabel("Full Name :", icon, JLabel.LEFT);

    JLabel label2 = new JLabel("Address :", JLabel.LEFT);
    label2.setIcon(new ImageIcon("b.png"));

    getContentPane().add(label1);
    getContentPane().add(label2);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    ImageIcon icon = new ImageIcon("r.gif");

    JButton b1 = new JButton("Regular", icon);
    p.add(b1);//  ww w  .  j a  v a  2s.  co  m

    Image image = GrayFilter.createDisabledImage(icon.getImage());
    JButton b2 = new JButton("GrayFilter", new ImageIcon(image));
    p.add(b2);

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:BasicDraw.java

public void paint(Graphics g) {

    ImageIcon icon = new ImageIcon("a.png");
    int x = 0;/*from   w ww. j av  a  2s . co m*/
    int y = 100;
    icon.paintIcon(this, g, x, y);
}