open.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new java.io.File("."));
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION){
System.out.println(fileChooser.getSelectedFile());
}
}
});
This might be a badly worded question but here we go:
I need this part of my code to produce ‘fileChooser.getSelectedFile());’ in a format that can be used elsewhere. I don’t mind if it is a variable (won’t really work because I need to call it in another actionListener) or (as I planned) output the selected folder as a string to an output file and then read that file in elsewhere in the program.
It’s important that the file path (e.g. C:/Users/Desktop/) be a String because that is what the class which will use the path takes in.
I’ve tried a couple of options but often get the “inconvertable types’ compile error etc, if anyone has any ideas they would share, that’d be great
Seems to fix it. Sorry to post and answer my own question. Figured out how to do it whilst I was waiting for replies. Seems like to be a string ‘exportPath’ has to have a string in it. In this case “\” but it can also be “” too.
No idea why but there you go 😀