PDA

Click to See Complete Forum and Search --> : File location


Greyskull
Mar 17th, 2008, 12:18 PM
hello,

the following code is an extract of my code


public FileChooserDemo()
{
fc = new JFileChooser();

fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

openButton = new JButton("Open a File...");
openButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == openButton) {
int returnVal = fc.showOpenDialog(FileChooserDemo.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
}


The jframe is set-up so that it contains a jtextarea and a jbutton (open file).
How can i get the path of the file(picture - ill expand the code so that it will only select pictures) selected by the user and place the path onto the textarea?

Thanks for any help and/or suggestions,

MonkOFox
Jun 4th, 2008, 11:31 AM
fc.getSelectedFile().getPath();

Justin Fox