swing - How to draw image using FileDialog in Java -


need display selected in filedialog image, thats somewhy didnt work. when try choose image throws exception javax.imageio.iioexception: can't create imageinputstream!

i think problem in getdirectory() , dont know how fix.

public imageshow() throws ioexception {     super("pictures");     setsize(1024,768);     setdefaultcloseoperation(windowconstants.exit_on_close);     setlocationrelativeto(null);      jpanel buttonpanel = new jpanel(new flowlayout());     buttonopen = new jbutton("open file");      buttonpanel.add(buttonopen);       actions();     filedialog();     add(buttonpanel);      image = imageio.read(new file(fd.getdirectory()));     imagelabel = new jlabel(new imageicon(image));     buttonpanel.add(imagelabel);  }   public void filedialog() {     fd = new filedialog(new jframe(), "choose file");     fd.setvisible(true); }     public void actions() {     buttonopen.addactionlistener(new actionlistener() {         @override         public void actionperformed(actionevent e) {             filedialog();         }     });  } 

}

image = imageio.read(new file(fd.getdirectory())); 

a directory not image! try instead getfile() which:

gets selected file of file dialog. if user selected cancel, returned file null.

but said in comments..

use swing based jfilechooser rather awt based filedialog.

and sure consult avialable documentation when using methods.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -