How do I load an image onto a JButton in an applet? new JButtion("foo.gif") throws a security exception.

John Zukowski

Passing a String to a JButton tries to load the image from a File. You need to create an ImageIcon with URL and pass that into the constructor:

URL picURL = getClass().getResource("mypic.gif");
ImageIcon icon = new ImageIcon(picURL);
JButton button = new JButton(icon);
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact