Displaying a file slected with a JFileChooser into a textarea
Hi,
I'm current struggling to display a file in a text area that needs to be selected with a JFileBrowser. I can manage to get the file browser to come up and select the file I wish to load but I can't seem to get the GUI working to display it in to a text area. I've shown my code below and any help would be great!
Thanks,
Sal
__________________________________________________ _______________
package openfile;
import java.io.File;
import javax.swing.*;
public class DisplayFile2 extends javax.swing.JFrame
{
private Object fileChooser;
/** Creates new form DisplayFile */
public DisplayFile2()
{
initComponents();
}
private void initComponents()
{
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* @param args the command line arguments
*/
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new DisplayFile2().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu fileMenu;
private javax.swing.JMenuItem helpContents;
private javax.swing.JMenu helpMenu;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem openMultipleFiles;
private javax.swing.JMenuItem openSingleFile;
private java.awt.TextArea textArea1;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
public class LoadMultipleFiles
{
/*public static void main(String[] args)*/
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
JFileChooser fileChooser = new JFileChooser(".");
fileChooser.setMultiSelectionEnabled(true);
int show = fileChooser.showOpenDialog(null);
if (show == JFileChooser.APPROVE_OPTION)
{
File selectedFiles[] = fileChooser.getSelectedFiles();
for (int selection = 0,
files = selectedFiles.length; selection <files; selection++)
{
System.out.println("Selected: "
+ selectedFiles[selection].getParent()
+ " --- "
+ selectedFiles[selection].getName());
}
}
}
});
}
}
}