import java.awt.*;
import javax.swing.*;
public class Program {
public static JButton button;
public static void main(String args[]){
JFrame win=new JFrame("title");
win.setVisible(true);
win.setSize(500,500);
win.setLayout(new FlowLayout());
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon i=new ImageIcon("icon.png");
button=new JButton("hello",i);
win.add(button);
button.setToolTipText("click me");
}
}
When I run the file , I just get the text "hello" on the button but no image.
(This image was downloaded from http://icons.iconarchive.com/icons/iynque/flat-ios7-style-documents/512/png-icon.png)
The image is stored in the project src file.
try this: ImageIcon i=new ImageIcon("src/icon.png");