java - JFileChooser on a Button Click -
i have button, clicking on want jfilechooser pop up. have tried this
jbutton browse= new jbutton("browse"); add(browse); browse.addactionlistener(new classbrowse()); public class classbrowse implements actionlistener { public void actionperformed(actionevent e) { int returnval = filechooser.showopendialog(this); if (returnval == jfilechooser.approve_option) { file file = filechooser.getselectedfile(); try { // return file path } catch (exception ex) { system.out.println("problem accessing file"+file.getabsolutepath()); } } else { system.out.println("file access cancelled user."); } } }
bhe above gives error the method showopendialog(component) in type jfilechooser not applicable arguments (classname.classbrowse)
also, want return complete file path. how do ?
actionlistener
notcomponent
, can't passthis
file chooser.- you @
file#getcanonicalpath
full path of file, can'treturn
it,actionperformed
returnsvoid
(or no return type). could, however, set other variable, call method or set text ofjlabel
orjtextfield
... example...
Comments
Post a Comment