Java ImageIcon create
import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; public class Main extends JFrame { public Main() { super("JButton"); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new FlowLayout()); Icon icon = new ImageIcon(getClass().getResource("icon.png")); //from w ww. j a v a 2 s .c om JButton closeButton1 = new JButton("Close", icon); getContentPane().add(closeButton1); } public static void main(String[] args) { Main frame = new Main(); frame.pack(); frame.setVisible(true); } }