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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -