I current have a JFrame application that uses JTextField’s for input of file location as per the code below.
txtSource = new JTextField();
txtSource.setToolTipText("/location/of/file/test.txt");
txtSource.setText("/location/of/file/test.txt");
txtSource.setBounds(16, 122, 412, 29);
contentPane.add(txtSource);
txtSource.setColumns(10);
What I would like to do is allow a directory search for the user to select the location of the file on the local computer and that location would populate into the Textbox.
I found the below information on JCHooser, but I’m not sure if this is way to go and would like assistance on how to implement.
String filename = File.separator+"tmp";
JFileChooser fc = new JFileChooser(new File(filename));
// Show open dialog; this method does not return until the dialog is closed
fc.showOpenDialog(frame);
File selFile = fc.getSelectedFile();
// Show save dialog; this method does not return until the dialog is closed
fc.showSaveDialog(frame);
selFile = fc.getSelectedFile();
Thanks in advance
Use
populates the text field with the selected file absolute file location