java - How to make the 'open with' dialog box? -
i made program search .txt files.
if click file means "open with" dialog box should appear, , dialog box contain list of installed programs.
i using code searching through files:
public file[] finder( string dirname) { // create file object on directory. file dir = new file(dirname); // return list of files in directory. return dir.listfiles(new filenamefilter(); } public boolean accept(file dir, string filename) { return filename.endswith(".txt"); }
what java code can use make "open with" dialog box appear?
you should use filechooser
this. take here:
//create file chooser final jfilechooser fc = new jfilechooser(); ... //in response button click: int returnval = fc.showopendialog(acomponent); public void actionperformed(actionevent e) { //handle open button action. if (e.getsource() == openbutton) { int returnval = fc.showopendialog(filechooserdemo.this); if (returnval == jfilechooser.approve_option) { file file = fc.getselectedfile(); //this real application open file. log.append("opening: " + file.getname() + "." + newline); } else { log.append("open command cancelled user." + newline); } } ... }
Comments
Post a Comment