I have a button, clicking on which I want the JFileChooser to pop up. I 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 the file path
} catch (Exception ex) {
System.out.println("problem accessing file"+file.getAbsolutePath());
}
}
else {
System.out.println("File access cancelled by user.");
}
}
}
Bhe above gives error The method showOpenDialog(Component) in the type JFileChooser is not applicable for the arguments (ClassName.ClassBrowse)
Also, I want it to return the complete file path. How do I do so ?