This is my first time using JFileChooser in Java and I’m currently attempting to convert the selected folder from a file type to a string such that I can write it to a JTextField on the GUI automatically so the user can confirm what they have selected.
The section of code I’m working on is as follows:
JButton btnSel1 = new JButton("Select...");
btnSel1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
fol1 = fc.getFileAsString(file);
rawIn1.setText(fol1);
}
}
});
welFrame.getContentPane().add(btnSel1, "6, 6, center, default");
Where I want the variable ‘fol1’ (folder 1) to be written into the JTextField ‘rawIn1’.
The method getFileAsString returns the the error “is undefined for the type JFileChooser”
Thanks in advance to anyone who looks over this for me.
Jared.
There’s no
getFileAsStringmethod inJFileChooser. You should useor
As the example in the documentation: