How to use JFileChooser to get filename of mutifile???

Hi,
I tryed to use JFileChooser to open multiple files and I want to save name of selected files in to array of String
I have writen some code but it doesn't work
My question is how can I get the filenames as a string array from
"getSelectedFiles". Any comments are highly welcomed! Thanks a lot. If yes pls give to me some code
Nguyen Thanh Ba

hope this will help
http://java.sun.com/developer/JDCTechTips/2004/tt0316.html

Similar Messages

  • RMI -How to use JFileChooser to see remote computer FileSystem

    i hav made a program in RMI which uses JFileChooser to show remote-machine File System. i have made my own FileSyatemView class (MyFileSyatemViewClient which extends FileSystemView) and override all the methods of FileSystemView Except getFileSystemView.
    Similarly i have made my own FileView(MyFileViewClient).
    i fed these to the JFileChooser. And object of JFileChooser i am recieving from the server through remote method getFileChooser(). Thus the code is like:
                             MyFileSystemViewClient mfsvc; //Defined Globally
                             MyFileViewClient mfvc; //Defined Globally
    public void actionPerformed(ActionEvent ae)
    if(ae.getActionCommand().equals("Open"))
                             mfsvc = new MyFileSystemViewClient();
                             mfvc = new MyFileViewClient();
    try
    JFileChooser jfc=fi.getFileChooser();
    // "fi" is the FileInterface through which we access server-side methods.
                                  jfc.setFileSystemView(mfsvc);
                                  jfc.setFileView(mfvc);                              
                                  int retval = jfc.showOpenDialog(null);
                                  if(retval==JFileChooser.APPROVE_OPTION)
                                       getf = jfc.getSelectedFile();
                             catch(Exception e)
                                  System.out.println("Error Occurred In OPEN :"+e);
    MyFileSystemViewClient class looks as :
    public class MyFileSystemViewClient extends FileSystemView
                   public MyFileSystemViewClient()
                        //super();
                        try{
                        fi.invokeMyFileSystemViewCons();
                        }catch(Exception e){
                             System.out.println("Error in invokeMyFileSystemViewCons : "+e);
                   public File[] getFiles(File file,boolean tr)
                        try{
                        return fi.getFiles(file,tr);
                        }catch(Exception e){
                             System.out.println("Error in getFiles : "+e);
                             return null;}
                   public File getHomeDirectory()
                        try{
                        return fi.getHomeDirectory();
                        }catch(Exception e){
                             System.out.println("Error in getHomeDirectory : "+e);
                             return null;}
                   public File getParentDirectory(File dir)
                        try{
                        return fi.getParentDirectory(dir);
                        }catch(Exception e){
                             System.out.println("Error in getParentDirectory : "+e);
                             return null;}
                   public File[] getRoots()
                        try{                         
                        return fi.getRoots();                    
                        }catch(Exception e){
                             System.out.println("Error in getRoots : "+e);
                             return null;}
                   public File getDefaultDirectory()
                        try{
                        return fi.getDefaultDirectory();
                        }catch(Exception e){
                             System.out.println("Error in getDefaultDirectory : "+e);
                             return null;}
                   public File createNewFolder(File containingDir)
                        try{
                        return fi.createNewFolder(containingDir);
                        }catch(Exception e){
                             System.out.println("Error in createNewFolder : "+e);
                             return null;}
                   public String getSystemDisplayName(File f)
                        try{
                        return fi.getSystemDisplayName(f);
                        }catch(Exception e){
                             System.out.println("Error in getSystemDisplayName : "+e);
                             return null;}
                   public String getSystemTypeDescription(File f)
                        try{
                        return fi.getSystemTypeDescription(f);
                        }catch(Exception e){
                             System.out.println("Error in getSystemTypeDescription : "+e);
                             return null;}
                   public File getChild(File parent, String fileName)
                        try{
                        System.out.println("Child FIle : "+fi.getChild(parent,fileName));
                        return fi.getChild(parent,fileName);
                        }catch(Exception e){
                             System.out.println("Error in getChild : "+e);
                             return null;}
                   public boolean isParent(File folder,File file)
                        try
                             return fi.isParent(folder,file);
                        catch(Exception e)
                        System.out.println("Error in isParent : "+e);
                             return false;     
                   public Icon getSystemIcon(File f)
                        try{
                        return fi.getSystemIcon(f);
                        catch(Exception e)
                        System.out.println("Error in getSystemIcon : "+e);
                             return null;     
                   public boolean isDrive(File dir)
                        try{
                        return fi.isDrive(dir);
                        catch(Exception e)
                        System.out.println("Error in isDrive : "+e);
                             return false;     
                   public boolean isFileSystem(File f)
                        try{
                        return fi.isFileSystem(f);
                        catch(Exception e)
                        System.out.println("Error in isFileSystem : "+e);
                             return false;     
                   public boolean isFileSystemRoot(File dir)
                        try{
                        return fi.isFileSystemRoot(dir);
                        catch(Exception e)
                        System.out.println("Error in isFileSystemRoot : "+e);
                             return false;     
                   public boolean isFloppyDrive(File dir)
                        try{
                        return fi.isFloppyDrive(dir);
                        catch(Exception e)
                        System.out.println("Error in isFloppyDrive : "+e);
                             return false;     
                   public boolean isRoot(File f)
                        try{
                        return fi.isRoot(f);
                        catch(Exception e)
                        System.out.println("Error in isRoot : "+e);
                             return false;     
                   public Boolean isTraversable(File f)
                        try{
                        return fi.isTraversable(f);
                        catch(Exception e)
                        System.out.println("Error in isTraversable : "+e);
                             return null;     
    //.....................................................End of the MyFileSystemViewClient.......................
    Thus each method in the class MyFileViewClient brings the required information from the server. BUT we are getting two problems:
    1) so many folders at the server-side are shown as files in the dialogbox.
    2)dialog box shows all "folders of the desktop" of the local filesystem and some more "local drives without any name". when i click a folder in the dialog box which is on my local machine, nothing happens. they are just the icon with the name but don't show the content. although i can easily see the drives of the remote filesystem and browse through except for the problem stated above at no.1.
    ok guys now its your turn to speak up.....
    plz give some suggestions and comments..
    ciao!!

    sry to all friends there who can't read the code clearly. as per the suggestion i am putting the code afresh..
    the main client class which binds to the server contains following piece of code :
    MyFileSystemViewClient mfsvc; //Defined Globally
    MyFileViewClient mfvc; //Defined Globally
    public void actionPerformed(ActionEvent ae)
         if(ae.getActionCommand().equals("Open"))
              mfsvc = new MyFileSystemViewClient();
              mfvc = new MyFileViewClient();
              try
                   JFileChooser jfc=fi.getFileChooser();//Requesting JFileChooser object from server.
                   // "fi" is the FileInterface through which we access server-side methods.
                   jfc.setFileSystemView(mfsvc);
                   jfc.setFileView(mfvc);
                   int retval = jfc.showOpenDialog(null);
                   if(retval==JFileChooser.APPROVE_OPTION)
                   getf = jfc.getSelectedFile();
              catch(Exception e)
              System.out.println("Error Occurred In OPEN :"+e);
    }i again like to convey that, "fi" is the FileInterface through which we access server-side methods.
    MyFileSystemViewClient class looks as :
    public class MyFileSystemViewClient extends FileSystemView
                   public MyFileSystemViewClient()
                        //super();
                        try{
                        fi.invokeMyFileSystemViewCons();
                        }catch(Exception e){
                             System.out.println("Error in invokeMyFileSystemViewCons : "+e);
                   public File[] getFiles(File file,boolean tr)
                        try{
                        return fi.getFiles(file,tr);
                        }catch(Exception e){
                             System.out.println("Error in getFiles : "+e);
                             return null;}
                   public File getHomeDirectory()
                        try{
                        return fi.getHomeDirectory();
                        }catch(Exception e){
                             System.out.println("Error in getHomeDirectory : "+e);
                             return null;}
                   public File getParentDirectory(File dir)
                        try{
                        return fi.getParentDirectory(dir);
                        }catch(Exception e){
                             System.out.println("Error in getParentDirectory : "+e);
                             return null;}
                   public File[] getRoots()
                        try{                         
                        return fi.getRoots();                    
                        }catch(Exception e){
                             System.out.println("Error in getRoots : "+e);
                             return null;}
                   public File getDefaultDirectory()
                        try{
                        return fi.getDefaultDirectory();
                        }catch(Exception e){
                             System.out.println("Error in getDefaultDirectory : "+e);
                             return null;}
                   public File createNewFolder(File containingDir)
                        try{
                        return fi.createNewFolder(containingDir);
                        }catch(Exception e){
                             System.out.println("Error in createNewFolder : "+e);
                             return null;}
                   public String getSystemDisplayName(File f)
                        try{
                        return fi.getSystemDisplayName(f);
                        }catch(Exception e){
                             System.out.println("Error in getSystemDisplayName : "+e);
                             return null;}
                   public String getSystemTypeDescription(File f)
                        try{
                        return fi.getSystemTypeDescription(f);
                        }catch(Exception e){
                             System.out.println("Error in getSystemTypeDescription : "+e);
                             return null;}
                   public File getChild(File parent, String fileName)
                        try{
                        System.out.println("Child FIle : "+fi.getChild(parent,fileName));
                        return fi.getChild(parent,fileName);
                        }catch(Exception e){
                             System.out.println("Error in getChild : "+e);
                             return null;}
                   public boolean isParent(File folder,File file)
                        try
                             return fi.isParent(folder,file);
                        catch(Exception e)
                        System.out.println("Error in isParent : "+e);
                             return false;     
                   public Icon getSystemIcon(File f)
                        try{
                        return fi.getSystemIcon(f);
                        catch(Exception e)
                        System.out.println("Error in getSystemIcon : "+e);
                             return null;     
                   public boolean isDrive(File dir)
                        try{
                        return fi.isDrive(dir);
                        catch(Exception e)
                        System.out.println("Error in isDrive : "+e);
                             return false;     
                   public boolean isFileSystem(File f)
                        try{
                        return fi.isFileSystem(f);
                        catch(Exception e)
                        System.out.println("Error in isFileSystem : "+e);
                             return false;     
                   public boolean isFileSystemRoot(File dir)
                        try{
                        return fi.isFileSystemRoot(dir);
                        catch(Exception e)
                        System.out.println("Error in isFileSystemRoot : "+e);
                             return false;     
                   public boolean isFloppyDrive(File dir)
                        try{
                        return fi.isFloppyDrive(dir);
                        catch(Exception e)
                        System.out.println("Error in isFloppyDrive : "+e);
                             return false;     
                   public boolean isRoot(File f)
                        try{
                        return fi.isRoot(f);
                        catch(Exception e)
                        System.out.println("Error in isRoot : "+e);
                             return false;     
                   public Boolean isTraversable(File f)
                        try{
                        return fi.isTraversable(f);
                        catch(Exception e)
                        System.out.println("Error in isTraversable : "+e);
                             return null;     
    //--------------------------------------------------------------------

  • How to use reflection to get base classes protected field

    I have one base Base classes which have protected fields and public get method to get the field.
    class Base
    protected int proField;
    public int getProField(){return proField;}
    Class Derive extends base class Base
    class Derive extends Base implements OtherInterface
    public void funtion(){};
    Now I have an instance of Derive, how can I use reflection to get the protected field inherited from Base. It seems Java Reflection only give runtime accessibility to public field and decleared field, protected-inherited field is excluded.
    Thanks
    Lei

    as the last poster said, traverse up the class hierarchy.
    ex:
    private void doSumfinToField(String fieldName throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException {
    Class clazz = getClass();
    Field field = findFieldInClass(clazz, fieldName);
    //field.doSumfin;
    private Field findFieldInClass(Class clazz, String fieldName) throws NoSuchFieldException {
    try { // to find the field in this class    
    return clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {
    // if we don't have a superclass, continue
    if (clazz.getSuperclass().equals(Object.class)) {
    throw e;
    // check in the superclass
    return findFieldInClass(clazz.getSuperclass(), fieldName);
    }

  • How to use PDPageEnumContents to get PDText?

    Please help me to use PDPageEnumContents to get PDText, the callback and PDGraphic confused me. I donnot know how to write. I am a green hand in Plugin Development.
    Thank you.
    Jason Wang

    This is an obsolete method. It should no longer be used.
    Aandi Inston

  • How to use JFileChooser to select only hard drive?

    I am doing CD update. I am using a component called "JFileChooser". I use this component to let user choose a Hard Drive or Floopy. When I try this component, and if I choose a hard drive and a folder/file, it works. If I only choose hard drive, it will return "My Documents"??? I cann't get hard drive. How to set up JFileChooser so user only choose hard drive and it will return this hard drive. Thanks for help.
    Gary

    Easiest (and maybe most portable) way is to have a specific file in your root directory of the CDROM. You could use java.io.File.listRoots() to get all drives and then pick the one that has your file.
    This will enable the user to copy the CDROM to a hard drive (easier for testing also) or mount a remote CDROM.

  • How to use JFileChooser

    Hi friends.. I developed my entire java application in an exe. If i click that exe,a JFrame window opened in that JFileChooser dialog box opened.Using that JFileChooser iam selecting a folder.In that folder i need to save my jar file which is encapsulated with exe.i need to store that jar file in that selected location.can anyone know how to save the jar file within the exe to the required location of the hard disk.Thanks in advance...

    I guess he want to write the jar-file ... and don't know how to get this.
    When the app is only an exe.
    By the way for storing only some kind of file-object you can
    use a FileOutputStream as bsampieri wrote.
    Olek

  • How to use sdk to get the image in the pdf file created by illustrator?

    I have some pdf files create by illustrator and saved as pdf documents,
    now I want to use the sdk to get the image in pdf files.
    how to?
    Thanks.

    Thank you first!
    Yes,you are right,since I am new to illustrator,and I want to try to write a plugin,
    I have read the sdk doc and API and opened the sample in vs2010,but no idea about how to operate the pdf doc in illustrator with api.
    Hope more advise or any examples,thank a lot.

  • I'm new to iPad and have downloaded the Nook app but don't know how to use it to get Nook books to download from my account at BN.

    I am new to iPad and have downloaded the Nook app.  How do I use it to read the Nook books are that in my account from Barnes&Noble?

    From http://www.barnesandnoble.com/ebooks/help-faqs.asp#NOOKapp
    How do I download my books to my device? I get a message "Safari cannot Download".Launch the NOOK app software to trigger the automatic syncing of your purchases to your device. You can also manually tap the 'gear' button in the lower right-hand corner of the navigation bar and then hit Account Settings. This will open a screen to allow you to enter your login information which includes your account name and password. Press Go and your information will be verified and then the contents of your on-line NOOK Library will be listed for you. Then just browse your book listings and tap on the book you'd like to download to your device. A popup will confirm your request. Press OK and the book will download to your device in the background, and you'll be notified when it has finished downloading.

  • How to use script to get the first table row on each page?

    I create a print form to display a table. I set a conditional page break on this table, so the table rows on each page could be different.
    For example, there're total 50 rows in this table. On the 1st page, there're 5 rows, but on the 2nd page, there're only 2 rows, and so on...
    Now I want to get some value from the 1st table row on each page. How can do that? I can refer to a table row using TableRow[n], but I don't know how to calculate 'n' in script (either FormCalc or JavaScript) for the 1st row on each page.
    Any ideas?

    Hi Wei,
    There is an option of setting the overflow header in the pallette. You may check that out. It is basically used to have the table header to be seen in all pages, if the table is overflowing to multiple pages. You may put your first row as the overflow header.
    - hope this helps, Kindly update,
    thanks and regards,
    - anto.

  • JNI: How to use FindClass to get a class in a Jar file?

    Is it possible to use the FindClass method of the JNI environment object to get a class that is in a jar file? My sample application was working when my class files were in the local directory. Now that I have replaced the class files with a jar file containing the classes, the app no longer works. I'd appreciate tips from anyone who knows how to do this.
    -Andreas

    Is it possible to use the FindClass method of the
    JNI environment object to get a class that is in a
    jar file? My sample application was working when my
    class files were in the local directory. Now that I
    have replaced the class files with a jar file
    containing the classes, the app no longer works. I'd
    appreciate tips from anyone who knows how to do this.It has nothing to do with JNI.
    The method uses the class path just like any other class loading situation in java. The reason it worked before is because your class path included the directory. It doesn't work now because either the jar is not in the class path or there is something wrong with the class path.

  • How to use MAP to get CALs license

    i want to use MAP detect CALs license on windows sever, exchange, SQL sever. can i use MAP to detect, how?

    See the Getting Started Guide for a list of supported server products for getting CAL info. For Windows Server, SQL Server, and SharePoint Server CAL info you need to enable logging on the supported servers and then import and parse those logs after they
    have been collecting the data for long enough. We recommend 90 days but you can work out the amount of logging that will be acceptable with your licensing professional. You can read how to configure the event logging in Section 1 of the Getting Started Guide.
    Exchange, SCCM, and Forefront Endpoint Protection will have data without importing logs by simply choosing those inventory scenarios in the wizard.
    Please remember to click "Mark as Answer" on the post that helps you, and to click
    "Unmark as Answer" if a marked post does not actually answer your question. Please
    VOTE as HELPFUL if the post helps you. This can be beneficial to other community members reading the thread.

  • How to use SYS_CONNECT_BU_PATH to get max(level)?

    This is the example from
    http://otn.oracle.com/products/oracle9i/daily/oct04.html
    How can I modify this query to get the max(level)?
    This query displays all levels 1, 2, 3
    SELECT employee_name, LEVEL,
    SYS_CONNECT_BY_PATH(employee_name, '/') "PATH"
    FROM employee
    START WITH employee_name = 'KING'
    CONNECT BY PRIOR employee_id = manager_id;
    This query returns the employee name and the management chain for each employee starting with the employee 'KING.' The results, using the same values shown in the first example, would look like:
    EMPLOYEE_NAME PATH LEVEL
    King /King 1
    Greenberg /King/Greenberg 2
    Faviet /King/Greenberg/Faviet 3
    Chen /King/Greenberg/Chen 3
    Sciarra /King/Greenberg/Sciarra 3
    Urman /King/Greenberg/Urman 3
    Popp /King/Greenberg/Popp 3
    My question is -
    How can I modify this query to get the max(level)?
    ie - only these records -
    Faviet /King/Greenberg/Faviet 3
    Chen /King/Greenberg/Chen 3
    Sciarra /King/Greenberg/Sciarra 3
    Urman /King/Greenberg/Urman 3
    Popp /King/Greenberg/Popp 3

    sql>select level, sys_connect_by_path(e.ename, '/') path
      2    from emp e
      3   where level = (select max(level)                 
      4                    from emp
      5                   start with mgr is null
      6                   connect by prior empno = mgr)
      7   start with mgr is null
      8   connect by prior empno = mgr;
        LEVEL PATH
            4 /KING/JONES/SCOTT/ADAMS
            4 /KING/JONES/FORD/SMITH
    2 rows selected.
    sql>select level, sys_connect_by_path(e.ename, '/') path
      2    from emp e
      3   where level = (select max(level) - 1             
      4                    from emp
      5                   start with mgr is null
      6                   connect by prior empno = mgr)
      7   start with mgr is null
      8   connect by prior empno = mgr;
        LEVEL PATH
            3 /KING/JONES/SCOTT
            3 /KING/JONES/FORD
            3 /KING/BLAKE/ALLEN
            3 /KING/BLAKE/WARD
            3 /KING/BLAKE/MARTIN
            3 /KING/BLAKE/TURNER
            3 /KING/BLAKE/JAMES
            3 /KING/CLARK/MILLER
    8 rows selected.

  • How to use apdu to get the certificate in smartcard?

    hi,guys
    how could i use the apdu command to get the certificate in smart card.
    now i sent following commands in JCOP shell
    /send 00a404000cA000000063504B43532D3135
    /send 00a4000c023f00
    /send 00a4000c025031
    /send 00a40200024404
    /send 00b0000080
    /send 00b0008080
    what's the next step?

    i'm using the A.E.T's safesign card,i just only use the apdu to load from card.
    but it's seems like it's can't load whole certificate.

  • How to use SPMetal to get the item's original field which named 'Created'

    I want to read the field which named 'Created' by using SPMetal,I found the 'Item' class has the property named '_originalValues', it seems to get the infomation about the original values.
    Is there anyone who has solved this kind of problems?

    Hi,
    By default, the Created, CreatedBy, Modified and ModifiedBy fields are not created by SPMetal, so we will need to extend our base entity class for accessing these fields in our
    code.
    Here is a link will show how to achieve this with steps in detail:
    http://weblogs.asp.net/uruit/archive/2011/05/05/linq-to-sharepoint-working-with-created-createdby-modified-and-modifiedby.aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • How to use G_SET_GET_ID_FROM_NAME to get set id

    hello gurus,
    i am having a set defined as CL-BOOK-DOC-TYPE which contians accounting document type
    i want to read the set values in my program using the function module G_SET_GET_ID_FROM_NAME  but when i try to pass this set value i am not getting any set values am i missing any key fields
    regards
    afzal

    self solved

Maybe you are looking for