java - Icon path for JFrame -
i need image icon on jframe dont want give path. using this
jlabel1.seticon(new javax.swing.imageicon("c:\\users\\abc\\desktop\\folder name\\1.jpg"));
because every system has different path , reason can not compile on other system(computer). need way can set image icon through file name only. , image in src
folder.
read image
embedded resource. new images
folder shown here needs available on classpath
public class imageapp { public static void main(string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { image image = null; try { image = imageio.read(getclass().getresource("/images/1.png")); } catch (ioexception e) { e.printstacktrace(); } jframe frame = new jframe("image app"); frame.add(new jlabel(new imageicon(image))); frame.pack(); frame.setvisible(true); } }); } }
Comments
Post a Comment