JFileChooser

Hello, well i am having problems understanding how JFileChooser works with the java.io.*; package. i am trying to open a document either with .doc or .txt extentions, but also add it to a JTextArea. but i have not idea of how to get the reading file working correctly and certainly i do not have an idea on putting it in the JTextArea object. i have read the io java package link in www.java.sun.com, but i did nbot understand it very well. can you help me solve this problem and give me a link that explains the io package better.

You completely miss the point....it's ONLY function is to present a directory structure which allows you to navigate and open a file. It does NOTHING with the file except let you ascertain the name, directory, extention of the file.
Anything else having to do with the file is handled by other controls.

Similar Messages

  • No Disk Error when opening JFileChooser

    Hi all
    After launching my app via JWS and opening my apps FileChooser I get a 'javaw.exe - No Disk' error message:
    'There is no disk in the drive. Please insert a disk into drive A:.'
    This doesn't happen if I start the app without JWS. Although it happens only the first time after opening the FileChooser it's rather annoying for the user. I can't expect the user always having a disk in their drive.
    Is there a way of switching the scan for drive A off?
    Thanks for your help.
    Stephan

    See Top 25 Bugparade: # 4264750
    This is a SecurityManager - Problem and the java.io.File.
    eg.:
    System.setSecurityManager(new RMISecurityManager());
    File[] roots = File.listRoots();
    Then you will see the problem...
    I tried the following workaround:
    before you access disk. (or JFileChooser)
    SecurityManager sm = System.getSecurityManger();
    System.setSecurityManager(null);
    // disable the SecurityManger
    // this special disk access needs no SecurityManager..
    ... popup JFileChosser or make FileAccess..
    System.setSecurityManager(sm);
    // restore the old SecurityManger
    It's not the best solution but it works..
    hope this will help,
    Wolfgang
    EDI Organisation

  • Can not sort the files in JFileChooser if the files are from remote machine

    Hi All,
    Let me set the context of the question.
    I have extended the JFileChooser to support the listing/view of files.dirs etc of remote location through CORBA.To achieve that i have customized
    my FileSystemView to support it. In general ,the current JFileChooser sorts the file when we have details view .My question is related to this.The default
    JFileChooser has the support for sorting but when i customized the FileSystemView,the sorting functionality is no more exist.I tried with TableRowSorter as well but
    the sorting can be achieved in View only,the model still remains same as initial.
    Any pointer towards this will be highly appreciated.
    Thanks
    Praveen

    Can anyone help me out to solve this problem or any suggestion regarding this ?
    Regards
    Praveen

  • JFileChooser (again!) slow in JRE 1.6.14 on some machines, not others

    I am running ImageJ (from the NIH) on several of our machines and on some machines JFileChooser is lightning fast, while others exhibit the same slowness spoken of in another JFileChooser thread that is now in a locked state. We open large image files (tif, png) located on our SAN and from the network traffic I see in Windows Task Manager while opening a folder containing the images I would guess that JFileChooser is actually opening the files (intentionally or not), not just obtaining a folder listing. It's similar to the same issue of opening a large folder of images with the view set to thumbnails - it takes about the same amount of time. I have tried the suggestions in that thread to no avail - the environment the machines are running is:
    Windows XP SP3
    Java JRE 1.6.0_14
    Can anyone comment on what JFileChooser is doing and how I can get it to stop this? Is it a Windows environment setting so that the native API calls made by JFileChooser will behave differently? Thoughts?
    Thanks,
    Tom

    I can't be absolutely sure, but we have several seemingly identical machines used for the purpose of reading medical images and several of them appear to work correctly (very fast loading and population of the folder's contents) and others don't. I have been using eclipse to enhance the software tool we're using (ImageJ) and using the debugger I can see that when the JFileChooser object is being instantiated and populated with entries a tremendous amount of network traffic occurs. This network traffic is equivalent to the amount I see when the same folder is opened in My Computer using a thumbnails view of the folder contents. Apparently, the network is delivering approximately 300-400 MB of images. As far as configuration of the Windows machines is concerned I haven't found a significant difference yet, though I admit I am not a Windows desktop admin and may not know of some configuration item that could be responsible. I assume (though could be mistaken) that both My Computer and JFileChooser are ultimately using similar API calls to get the folder content entries?

  • Problem with JFileChooser and ImageIcon

    I'm trying to create an ImageIcon object from file selected in JFileChooser. The problem is that jfc.getSelectedFile().getAbsolutePath() returns a string with backslashes and the constructor of ImageIcon requires the string to have slashes. I`ve tried to create it via URL but it doesn't work as well...
    String lastUsedPath;
    URL imageURL;
    JFileChooser fc = new JFileChooser();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    int returnVal = fc.showDialog(frame,title);
    if(returnVal==JFileChooser.APPROVE_OPTION){                    
         lastUsedPath = fc.getSelectedFile().getAbsolutePath();
         imageURL = getClass().getResource(lastUsedPath);     //don't really get this but I copied it from Java Swing Tutorial          
    }else{
         return null;
    int curH, curW;            
    ImageIcon srcIcon = new ImageIcon(imageURL);                              
    curW = srcIcon.getIconWidth();
    curH = srcIcon.getIconHeight();If I use it this way imageURL is set to null.
    If I set the imageURL as 'fc.getSelectedFile().toURL()' the string is eg.: "file:/E:/file.jpg" instead of "E:/file.jpg". After that the ImageIcon is created but width and height return -1.
    If I try to create ImageIcon by 'new ImageIcon(lastUsedPath)' I get a not null object but the width & height of the ImageIcon is -1 as well.
    What do I have to do to be able to create an ImageIcon from file selected in JFileChooser? Why is this so hard and mind blowing?

    It still returns the ImageIcon object with width & height set to -1.
    EDIT:
    Got it finally:
    lastUsedPathForStupidImageIcon = fc.getSelectedFile().getPath();     
    img = ImageIO.read(new File(lastUsedPathForStupidImageIcon));
    curH = img.getHeight(this);
    curW = img.getWidth(this);The key was to use another String variable and hold the path instead of the absolute path
    Edited by: Beholder on Jan 17, 2010 1:35 PM

  • JFileChooser animated gif preview

    I'm using an Accesory with an ImageIcon to preview images on a JFileChooser.
    It works ok, but I would like to know how do I get those animated gif to restart their animation whenever I click some other file (so the image preview goes to null) and click back on them.
    There are non-looped gifs and looped ones, it is specially for the non-looped gifs as to give a way to get to see the animation again. After clicking the file once the animation never plays again, even if a load another preview by clicking another file and then go back...
    Since there's no obvious method on ImageIcon or Image I tried flush since it says it clears the data but the only thing I got was the gif animating improperly (it would get trash/noise).
    * JFileChooserImagePreview.java
    * Created on 16 de junio de 2005, 12:58 AM
    package ptcg.win.util;
    import javax.swing.*;
    import java.beans.*;
    import java.awt.*;
    import java.io.File;
    /* from FileChooserDemo2.java. */
    public class JFileChooserImagePreview extends javax.swing.JComponent implements PropertyChangeListener {
         public JFileChooserImagePreview(JFileChooser fc) {
              setHeight = -1;
              setWidth = -1;
              setPreferredSize(new Dimension(100, 50));
              fc.addPropertyChangeListener(this);
         public JFileChooserImagePreview(JFileChooser fc, int setHeight, int setWidth) {
              this.setHeight = setHeight;
              this.setWidth = setWidth;
              setPreferredSize(new Dimension(setHeight, setWidth));
              fc.addPropertyChangeListener(this);
         public void propertyChange(PropertyChangeEvent e) {
              boolean update = false;
              String prop = e.getPropertyName();
              //If the directory changed, don't show an image.
              if(JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) {
                   file = null;
                   update = true;
              } else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
                   file = (File) e.getNewValue();
                   update = true;
              //Update the preview accordingly.
              if (update) {
                   thumbnail = null;
                   if(isShowing()) {
                        loadImage();
                        repaint();
         public void loadImage() {
              if (file == null) {
                   thumbnail = null;
                   return;
              ImageIcon tmpIcon = new ImageIcon(file.getPath());
              if (tmpIcon != null) {
                   Image i = tmpIcon.getImage();
                   //i.flush(); //screws the animation
                   thumbnail = new ImageIcon(i.getScaledInstance(setHeight, setWidth, Image.SCALE_SMOOTH));
         protected void paintComponent(Graphics g) {
              if (thumbnail == null) {
                   loadImage();
              if (thumbnail != null) {
                   int x = getWidth()/2 - thumbnail.getIconWidth()/2;
                   int y = getHeight()/2 - thumbnail.getIconHeight()/2;
                   if (y < 0) {
                        y = 0;
                   if (x < 5) {
                        x = 5;
                   thumbnail.paintIcon(this, g, x, y);
         ImageIcon thumbnail = null;
         File file = null;
         int setHeight, setWidth;
    }Thanks in advance

    Never-mind. I have it working properly now.

  • Problem in using JFileChooser

    Hi all
    i m using JFile chooser
    here is the code:(at class level)
    private JFileChooser fileChooser = new JFileChooser(){
    protected void fireActionPerformed(String command) {
    if (command != null && command.equals(JFileChooser.APPROVE_SELECTION)) {
    super.fireActionPerformed(command);
    when i open the form, following exception arises.
    java.io.IOException
         at sun.awt.image.GifImageDecoder.readHeader(GifImageDecoder.java:337)
         at sun.awt.image.GifImageDecoder.produceImage(GifImageDecoder.java:123)
         at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:254)
         at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
         at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    however it is not hindering my work, but why it is...
    Pls help

    Hi all,
    I think no one in the bord knows the answer.
    or the problem is so trivial that, no one want to reply.....
    whatever may be the reason....Pls help me , if some one know about this...
    Thanx,
    Manish ...

  • How do I change the text on my JFileChooser?

    Hello,
    I have a JFileChooser that is set to only select directories because... I need the user to only open directories. The problem is, whenever it comes up, in the text field at the bottom (next to the approve button) has the full path of the current directory in it. Some users are confused by this, not knowing if that text is supposed to be erased or not. Is there any way to get rid of the text so that it is a blank text field? setSelectedFile() does not work because I am using directory selection mode, not file selection mode.
    Thanks for any responses,
    Eric

    import darrylbu.util.SwingUtils;
    import javax.swing.JFileChooser;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class FileChooserBlankTextField {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                JTextField textField =
                      SwingUtils.getDescendantOfType(JTextField.class, chooser,
                      "Enabled", true);
                textField.setText("");
                chooser.showOpenDialog(null);
    }You can get the SwingUtils class [_here_|http://tips4java.wordpress.com/2008/11/13/swing-utils/]
    db

  • How to make JFileChooser's directory as a droptarget?

    i able to drop file in the current directory of JFileChooser (on the "look in" of it e.g look in c:\) but when i drop my file to JFileChooser any of the directories which jfilechooser shows mouse cursor shows the disable symbol which indicates that this directory doesn't support drop target i also tried for writable directory but the problem is same.
    this is my code
    File node = chooser.getCurrentDirectory();
         // Only allow a drop on a writable directory
          if (node.isDirectory()) {
            try {
             File f = new File(node.getPath());
             if (f.canWrite()) {
                return f;
            } catch (Exception e) {
          }i think it is the problem of chooser,getCurrentDirectory(); statement.
    what should i have to place instead of this statement.
    Plz help me.

    Note: This thread was originally posted in the [New To Java|http://forums.sun.com/forum.jspa?forumID=54] forum, but moved to this forum for closer topic alignment.

  • How to close JFileChooser dialog only while using ESC key ?

    Hi All,
    I am using a Frame and from this frame i am calling the JFileChooser via a JButton.
    and using JFileChooser ShowOpenDialog() for open and close .
    while doing ESC operation my Main Frame is getting closed with JFileChooser dialog.
    Can i close only JFileChooser dialog while doing ESCAPE key operation.
    I Have Escape key function in Main Frame file and JFileChooser file( EscKeyEventActionIntialization)
    But while debuging i am not able to catch the esc key action inside EscKeyEventActionIntialization.
    I have attached the code, please suggest me , if i need to do any change .
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package MainPackage;
    import javax.swing.filechooser.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.*;
    public class SourceSettings extends javax.swing.JDialog{
        JDialog dialog;
        private javax.swing.JFileChooser jFileChooser1;
        MainFile  mainFile;
        ImageIcon icon = new ImageIcon(getClass().getResource("/Resource/mchpIcon.GIF"));
        /** Creates new form SourceSetting */
        public SourceSettings(MainFile  pMPFS) {
            dialog = new JDialog();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            mainFile = pMPFS;
            jFileChooser1 = new javax.swing.JFileChooser();
            dialog.add(jFileChooser1);
            EscKeyEventActionIntialization();
            jFileChooser1.setDialogTitle("Browse For Folder");
            jFileChooser1.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 11)); // NOI18N
            jFileChooser1.setName("Browse For Folder"); // NOI18N
        public String getDirctoryPath()
            int retval = jFileChooser1.showOpenDialog(dialog);
            dialog.setVisible(true);
            if(retval  == JFileChooser.APPROVE_OPTION)
                return jFileChooser1.getSelectedFile().getAbsolutePath().toString();
            else
                dialog.setVisible(false);
                dialog.dispose();
                return null;
        public String getParentDirctoryPath()
            return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
        public String getOutputDirctoryPath()
            if(jFileChooser1.showOpenDialog(mainMpfs)  == JFileChooser.APPROVE_OPTION)
               return jFileChooser1.getCurrentDirectory().getAbsolutePath().toString();
            else
               dialog.dispose();
               return null;
        private void EscKeyEventActionIntialization()
            Action  ESCactionListener = new AbstractAction () {
              public void actionPerformed(ActionEvent actionEvent) {
                dialog.setVisible(false);
                dialog.dispose();
            KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
            JComponent comp = dialog.getRootPane();
            comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "ESCAPE");
            ActionMap actionMap = comp.getActionMap();
            actionMap.put("ESCAPE", ESCactionListener);
    }

    You have a class that extends JDialog and has a JDialog member variable (very confusing), and no main(...) method. How is the class used as a JDialog?
    To get better help sooner, post a SSCCE that clearly demonstrates your problem. Note that this should be executable and should not contain any extraneous code.
    db

  • How can I set a default file for JFileChooser

    Hi. I am developing a p2p chat application and I have to unrelated questions.
    1. How can I set a default file name for JFileChooser, to save a completly new file?
    2. I have a JTextArea that I append recieved messages. But when a message is appended, the whole desktop screen refreshes. How can I prevent that?
    Hope I was clear. Thanks in advance.

    Thank you for the first answer, it solved my problem. Here is the code for 2nd question, I've trimmed it a lot, hope I didn't cut off any critical code
    public class ConversationWindow extends JFrame implements KeyListener,MessageArrivedListener,ActionListener,IOnlineUsrComp{
         private TextArea incomingArea;
         private Conversation conversation;
         private JTextField outgoingField;
         private JScrollPane incomingTextScroller;
         private String userName;
         private JButton inviteButton;
         private JButton sendFileButton;
         private JFileChooser fileChooser;
         private FontMetrics fontMetrics;
         private HashMap<String, String> onlineUserMap;
         public void MessageArrived(MessageArrivedEvent e) {
              showMessage(e.getArrivedMessage());
         public ConversationWindow(Conversation conversation)
              this.conversation=conversation;
              userName=User.getInstance().getUserName();
              sendFileButton=new JButton("Dosya G�nder");
              sendFileButton.addActionListener(this);
              inviteButton=new JButton("Davet et");
              inviteButton.addActionListener(this);
              incomingArea=new TextArea();
              incomingArea.setEditable(false);
              incomingArea.setFont(new Font("Verdana",Font.PLAIN,12));
              fontMetrics =incomingArea.getFontMetrics(incomingArea.getFont());
              incomingArea.setPreferredSize(new Dimension(300,300));
              outgoingField=new JTextField();
              outgoingField.addKeyListener(this);
              incomingTextScroller=new JScrollPane(incomingArea);          
              JPanel panel=new JPanel();
              panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS));
              panel.add(inviteButton);
              panel.add(sendFileButton);
              panel.add(incomingTextScroller);
              panel.add(outgoingField);
              add(panel);
              pack();
              setTitle("Ki&#351;iler:");
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setLocationRelativeTo(null);
              addWindowListener(new CloseAdapter());
         //Sends the message to other end
         public void keyPressed(KeyEvent e) {
              if(e.getKeyCode()==KeyEvent.VK_ENTER && e.getSource()==outgoingField)
                   String message=outgoingField.getText();
                   if(message.equals("")) return;
                   showMessage(userName+": "+message);
                   conversation.sendMessages(userName+": "+message);
                   outgoingField.setText("");     
         //Displays the recieved message
         public void showMessage(String message)
              if(fontMetrics.stringWidth(message)>incomingArea.getWidth())
                   int mid=message.length()/2;
                   StringBuilder sbld=new StringBuilder(message);
                   for(;mid<message.length();mid++)
                        if(message.charAt(mid)==' ')
                             sbld.setCharAt(mid, '\n');
                             message=sbld.toString();
                             break;
              incomingArea.append("\n"+message);
    }

  • How can I get an extension from a file...in JFileChooser

    I have got a problem here. Here I have a JFileChooser, I want to add in
    a FileFilter, and user could only see some type of file. But as long as I
    try to get the extension....It wont compile, could any one teach me how
    to get the extension of a file in JFILECHOOSER???
    ============================================
    import java.io.*;
    import java.io.File.*;
    import javax.swing.filechooser.FileFilter;
    public class MainFrame extends JFrame implements ActionListener {
    public MainFrame() {.............}
    private boolean chooseFile()
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
    FileChoser filtering = new FileChoser("txt");
    fileChooser.setFileFilter(filtering);
    fileChooser.addChoosableFileFilter(filtering);
    int selection = fileChooser.showOpenDialog( this );
    if ( selection == JFileChooser.CANCEL_OPTION )
    return false;
    if (selection == -1) {
    return false;
    File tmpfile = fileChooser.getSelectedFile();
    filename = tmpfile.toString();
    setTitle( "Smiggin Holes 2010 - " + filename );
    return true;
    static class FileChoser extends javax.swing.filechooser.FileFilter
    String extension;
    String description;
    public FileChoser(String extension, String description){
    this.extension = extension;
    this.extension = description;
    // Accept all directories and all gif, jpg, or tiff files.
    public boolean accept(File f)
    if (f != null)
    if (f.isDirectory())
    return true;
    String ext = getExtension(f); //<<<<<<<<<<<THE PROBLEM IS HERE WHEN I TRY TO GET THE EXTENSION OF THE FILE. IT CANT COMPILE
    System.out.println("aasdfasdf"+ext);
    if ((ext!=null)&&(ext.equals(extension)))
    return true;
    return false;
    // The description of this filter
    public String getDescription() {
    return "Just Text Files";
    ======================================
    Could you tell me what can I do? To get the extension of the file selected by the user?
    And What do I have to change?
    Regards,

    Hi,
    can you post your compile error and the code of getExtension().
    Regards
    Ldinka

  • File size using JFileChooser

    Hi,
    I have a File[] array (with directories and files on it), and want to take to another array the size of files only. I don't want to use File.length, because in this way i take the size of directories too.
    I tried to use this:
    for(int i=0; i<array.length; i++)
    File f = new File(path, array.toString());
    Size[i]=f.length();
    }//for
    but i don't think is good to have a Size array with "zeros" (when it finds directories) and long values (when it finds files).
    What do you propose me to do?
    Would it be good to use JFileChooser and how?
    Thanks,
    TSolonel

    What do you want to do with that array? Why not having a File[] array, so you have both length and isDirectory info. Sorting? Something else? JFileChooser seems irrelevant. But again, it's all up to what you are trying to do. Clarify

  • Problems with JFileChooser and Windows 2000 (can't see mydocuments contents

    Hi! I've an applet which has a JFileChooser component. In other Windows, I can select the MyDocuments folder and it goes there and list all the contents OK. But, in Windows 2000, when I go to MyDocuments, none of the contents is listed in the file chooser. I need to navigate through all the directories to get there (C:\documents and settings\user\my documents) and then, it shows its contents, but obviously, I don't want it to be this way because is difficult for the common user.
    Any idea of why is going on this?
    Thanks in advance!

    Hello, You need to use something like o=isp as the
    root DN, then o=yourorg.com goes beneath it.
    i.e.
    For the other questions on setup, just choose o=isp
    as base DN when you set up the directory server. When
    you run ims_dssetup.pl, choose o=internet as the DC
    tree base, then choose o=isp as the user/groups base
    suffix.
    When you are installing messaging server it will ask
    where to put the default organization, this is where
    you would choose o=abc.com, o=isp
    For more info on how this structure works please take
    a look at this link and it will all fit into place:
    http://docs.sun.com/source/816-6017-10/changes.htm#170
    8Alright, I got ims_dssetup to run successfully. But now when the ims 5.2 installation is about 50% done, I get the message:
    A serious problem occurred while installing the iPlanet Messaging Server Messaging SIE entry in LDAP (msg.cfgldap.sie.inf). It reported the following problem:
    The server configuration for the Messaging SIE entry in LDAP (msg.cfgldap.sie.inf) cannot be created.

  • JFileChooser problem with Windows Vista

    Hi,
    I running into the following problem.
    I am using JFileChooser in some of the JInternalFrames in my application. When I using Windows XP everthing works perfectly.
    Now Here is the issues, I have a new user using the application. His computer is Windows Vista and the error comes when I am using JFileChooser.
    I need to know I need to put another file or update ANYTHING ON WINDOWS VISTA FOR THIS JFileChooser to work.
    I appreacite your help and time.
    Wilfer
    CDC

    That's not an error from Java, as far as I know. Something else is producing it. Look over these search results for a case that matches what you see:
    http://www.google.com/search?q=error+31849

  • Applet with JFilechooser called from a Javascript blocks paint messages

    Hi,
    I am trying to create an applet that can:
    1) be called from a Javascript
    2) displays a file selection dialog for multi-selecting files
    3) returns the selected filenames in a string to the JavaScript
    I am able to use doPrivileged to apply the necessary security context to launch a JFilechooser and return the filenames selected. However, When the JFilechooser dialog is visible and the user moves the dialog window around the HTML pages dose not receive any repaint messages. They seem to be blocked by the thread that launched the JFilechooser dialog and is probably blocking update events as the dialog is still visible.
    I know I need some type of a message pump so the child thread can inform the parent thread and the browser to repaint. However, I don't know how to do this.
    Please help.
    ------Applet Code Begin:-----
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.AWTEvent;
    import java.awt.event.AWTEventListener.*;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.util.Locale;
    import java.util.MissingResourceException;
    import java.util.Properties;
    import java.util.ResourceBundle;
    import java.util.Vector;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    public class SampleApplet extends JApplet
       boolean allowDirs=false;
       boolean allowFiles=true;
       boolean hidden=false;
       File lastUserDir=null;
       public void init()
        public void start()
        public void stop()
        public String selectFiles()
           String choosenFiles = null;
           choosenFiles = new String((String)java.security.AccessController.doPrivileged(
           new java.security.PrivilegedAction()
         public Object run()
            String choosenFiles=new String();
                 JFilechooser fc = new JFilechooser();
         fc.setFileSelectionMode(allowDirs ? (allowFiles ? JFileChooser.FILES_AND_DIRECTORIES
            : JFileChooser.DIRECTORIES_ONLY)
            : JFileChooser.FILES_ONLY);
         fc.setMultiSelectionEnabled(true);
                 int returnVal = fc.showOpenDialog(null);
                 if (returnVal == JFileChooser.APPROVE_OPTION)
                    choosenFiles = "The selected filesnames will be stuffed here";
              return choosenFiles; //return whatever you want
           return choosenFiles;   
    ------Applet Code End:-----
    ------Html Code Begin:-----
    <html>
    <applet id="SampleApplet" archive="SampleApplet.jar"; code="SampleApplet.class"; width="2" height="2" codebase=".">
    </applet>
    <head>
        <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    function SelectFiles_onclick()
      var s = (document.applets[0].selectFiles());
      alert(s);
    </script>
    </head>
    <body>
        Click Test button to select files
        <input id="SelectFiles" type="button" value="Select Files" onclick="return SelectFiles_onclick()" />
    </body>
    </html>
    ------Html Code End:-----

    try this:
    first don't open the file dialog in the SelectFiles call. Start a new thread that does that. Then return from the SelectFiles call immediately. Now after the user selectes the files call back into the javascript by doing something like this:
    pass the list of files into this function, each on being a String in the params array
        public synchronized void sendDataToUI(Object[] params) {
            if (FuserState.hasQuit()) {
                return;
            String function = "getUpdates";
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Calling Javascript function " + function);
            if (getJavaScriptWindow() == null) {
                logger.log(Level.SEVERE, "Member javascriptWindow is NULL, no call was made!");
                return;
            try {
                getJavaScriptWindow().call(function, params);
            catch (netscape.javascript.JSException x) {
                if (params == null) {
                    logger.log(Level.SEVERE, "p=NULL PARAM");
                } else {
                    logger.log(Level.SEVERE, "p=" + params[0]);
        protected JSObject getJavaScriptWindow() {
            javascriptWindow = JSObject.getWindow(this);
        }

Maybe you are looking for