Results 1 to 2 of 2
  1. #1
    happysal is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default 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());
    }
    }
    }
    });
    }

    }

    }

  2. #2
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by happysal View Post
    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.
    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

  1. [SOLVED] jfilechooser for saving a file....?
    By prabhurangan in forum AWT / Swing
    Replies: 10
    Last Post: 10-06-2013, 11:17 PM
  2. how to use JFileChooser to select file -> string
    By gezzel in forum AWT / Swing
    Replies: 15
    Last Post: 10-23-2008, 06:34 AM
  3. How can I include a html file in html textarea?
    By surya_dks in forum New To Java
    Replies: 2
    Last Post: 10-04-2008, 08:20 AM
  4. how to use JFileChooser to select file -> string
    By gezzel in forum New To Java
    Replies: 9
    Last Post: 09-18-2008, 10:45 PM
  5. TextArea Bug?
    By Soda in forum New To Java
    Replies: 2
    Last Post: 12-07-2007, 01:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •