Results 1 to 2 of 2
- 11-12-2008, 07:45 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 1
- Rep Power
- 0
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());
}
}
}
});
}
}
}
- 11-13-2008, 07:43 AM #2
Member
- Join Date
- Aug 2008
- Posts
- 58
- Rep Power
- 0
Hello ,
can you be more specific? what's not displayed? The content of the "choosen file" --- it that's the problem then where is the code to do the IO operation?
I didn't see any IO routine in the code above!
Or are you asking how to use JFileChooser, in that case did you have followed this one:
How to Use File Choosers (The Java™ Tutorials > Creating a GUI with JFC/Swing > Using Swing Components)
Similar Threads
-
[SOLVED] jfilechooser for saving a file....?
By prabhurangan in forum AWT / SwingReplies: 9Last Post: 03-19-2012, 05:20 PM -
how to use JFileChooser to select file -> string
By gezzel in forum AWT / SwingReplies: 15Last Post: 10-23-2008, 05:34 AM -
How can I include a html file in html textarea?
By surya_dks in forum New To JavaReplies: 2Last Post: 10-04-2008, 07:20 AM -
how to use JFileChooser to select file -> string
By gezzel in forum New To JavaReplies: 9Last Post: 09-18-2008, 09:45 PM -
TextArea Bug?
By Soda in forum New To JavaReplies: 2Last Post: 12-07-2007, 12:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks