why wont my gif display in my java pane?
I have knocked up a test program to fiddle with images in swing but cant get the image to show in a button on the pane although it shows in the top bar hence the path is right .. any suggestions as to what I am doing wrong.
The code sample is as follows:
package swingTest2;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class SwingTest2 extends JFrame{
public SwingTest2() {
// TODO Auto-generated constructor stub
super("Test Window");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
URL resourceLocation = getClass().getResource("/images/load.gif");
ImageIcon icon = new ImageIcon(resourceLocation);
setIconImage(icon.getImage());
JButton load = new JButton("Load");
JButton save = new JButton("Save");
pane.add(load,icon);
add(pane);
setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingTest2 s = new SwingTest2();
}
}
|