Mega Code Archive

 
Categories / Java / 2D Graphics GUI
 

Create Image Icon from PNG file

import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; public class PngIcon{   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);     frame.add(bt, BorderLayout.NORTH);     frame.add(lab, BorderLayout.SOUTH);     frame.setBounds(50, 50, 200, 200);     frame.setVisible(true);   }   public static void main(String[] args){     new PngIcon();   } }