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 ?

  1. actionlistener not component, can't pass this file chooser.
  2. you @ file#getcanonicalpath full path of file, can't return it, actionperformed returns void (or no return type). could, however, set other variable, call method or set text of jlabel or jtextfield ... example...

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -