Using jfilechooser

hi all,
how to use jfilechooser to select a file available in another computer of my LAN.
i used setFileSelectionMode(JFileChooser.FILES_ONLY);with this statement, if i give 'c:' or any local/mapped drive names in text box, it lists the files properly and i can choose the file.
but, if i give the IP address of another system, i.e like '\\192.168.0.243', it simply accepts this (\\192.168.0.243) as filename and closes the file chooser dialog. if i type the ip address, the file chooser should list the shared drives in that system.  how to do this?
i tried java.awt.filedialog, but it does this, but supports only single file selection
thanking you.

rnoack wrote:
1) i don't find it amusing that we are even having this conversation, it is immature and i have tried to end it twice now but you always seem to want to have the last word (which would be fine with me if it didn't negatively reflect on my intentions or values)The "problem" in this case is that is that Darryl.Burke is correct. Cross-posting is really rude, it means that you don't care about the time that people spend answering questions. Most frequenst posters at all forums and mailing lists will tell you that.
Cross-posting and not saying in the post that you are cross-posting is even worse. (Cross-posts are often removed from these forums).
>
2) i never did, and never will think that i can tell you want to do or not to do. i was merely offering advice which i feel and will continue to feel regardless of your beliefs is for the best of all related communities.Note that Darryl is a moderator and tried to tell you that you shouldn't cross-post. Most frequent posters would have done that if they had found out that you were cross-posting. The only mistake that Darryl did is that he thought that you were going to listen to his advice even if he didn't make that specific post as a moderator.
Kaj
Ps. I also blocked an abusive post.

Similar Messages

  • 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

  • How to get the file path of selected file using JFileChooser

    Hi All,
    I am trying to store the file on my FTP server after selecting the file from the user workstation using JFileChooser. But I am not able to write the file on FTP server or on user local machine where application is running. I am new to this FTP server coding. Can anyone help me in this.
    This is the code I wrote on button click user will able to select the file:
    String filename1;
    File file;
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(this);
    file = fc.getSelectedFile();
    filename1 = file.getPath();
    txtFilePath.setText(filename1);
    Below is the code to write the file on my local machine first:
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    outFile.write();
    outFile.flush( );
    outFile.close( );
    Any help will be greatly appriciated

    rp0428 wrote:
    >
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    >
    There is NOTHING named 'fileName' in any of the code you posted so that code can't possibly compile let alone actually run.
    How can anyone help you if you won't post the actual code you are using?Its just a random snippet of other code that is totally irrelevant to this thread if you ask me.

  • Get the file directory/location using JFileChooser

    Dear,
    How to get the file directory and it location with using JFilechooser after select the indicate file?
    Thanks

    There is an example at the top of JFileChooser's doc.
    http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFileChooser.html

  • Folders that having non-ascii chars are not displaying on MAC using JFileChooser

    On MAC OS X 10.8.2, I have latest Java 1.7.25 installed. When I run my simple java program which allows me to browse the files and folders of my native file system using JFileChooser, It does not show the folders that having non-ascii char in there name. According this link, this bug had been reported for Java 7 update 6. It was fixed in 7 Update 10. But I am getting this issue in Java 1.7.21 and Java 1.7.25.
    Sample Code-
    {code}
    public class Encoding {
    public static void main(String[] arg) {
    try {
    //NOTE : Here at desktop there is a folder DKF}æßj having spacial char in its name. That is not showing in file chooser as well as while is trying to read for FILE type, it is not identify by Dir as well as File - getting File Not Found Exception
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (IllegalAccessException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedLookAndFeelException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    Logger.getLogger(Encoding.class.getName()).log(Level.SEVERE, null, ex);
    JFileChooser chooser = new JFileChooser(".");
    chooser.showOpenDialog(null);
    {code}

    Hi,
    Did you try this link - osx - File.list() retrieves file names with NON-ASCII characters incorrectly on Mac OS X when using Java 7 from Oracle -…
    set the LANG environment variable. It's a GUI application that I want to deploy as an Mac OS X application, and doing so, the LSEnvironment setting
    <key>LSEnvironment</key> <dict> <key>LANG</key> <string>en_US.UTF-8</string> </dict>

  • How to save a copy of a file to different location using jfilechooser

    hi, this is ravikiran,
    In my project there is a situation where when a user clicks on some button, a copy of a file(which is initially in my project folder) must be saved to a location specified by the user.
    I have no idea how to do this using JFileChooser.
    help me,
    thanx in advance

    JFileChooser lets you choose a file. Once it's done you will have to program the copy function with womething like :
         public void copyToDir(String fileSource,String fileDest) {
              try {
                   FileChannel srcChannel = new FileInputStream(fileSource).getChannel();
                   FileChannel dstChannel = new FileOutputStream(fileDest).getChannel();
                   dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                   srcChannel.close();
                   dstChannel.force(true);
                   dstChannel.close();
              } catch (IOException e) {
                   e.printStackTrace();
         }

  • Using JFileChooser in GUI Builder / Matisse

    Would appreciate any help with how to modify the code created by the NetBeans GUI Builder / Matisse to use jFileChooser.
    I've added a Menu item to act as a file Open option, called OpenItem, and the GUI builder has added a listener which points to a method OpenItemActionPerformed:
    private void OpenItemActionPerformed(java.awt.event.ActionEvent evt) {                                        
            // TODO add your handling code here:
    } I have also added a jFileChooser component, named jFileChooser1, but if I try to use it in the OpenItemActionPerformed method I get an error.
    private void OpenItemActionPerformed(java.awt.event.ActionEvent evt) {                                        
           JFileChooser1.  
    }     shows error: "<identifier> expected" (as soon as I get to the dot).
    The variable seems to be defined:
    private void initComponents() {
            jFileChooser1 = new javax.swing.JFileChooser();
    }// Variables declaration - do not modify
    private javax.swing.JFileChooser jFileChooser1;
    // End of variables declaration
    Maybe I have gone about this the wrong way, so any clues as to either how I can get the jFileChooser1 variable to work or any way I can use JFilechooser with GUI Builder created application would be much appreciated.
    Thanx in advance.

    The following example creates a file chooser and displays it as first an open-file dialog and then as a save-file dialog:
        String filename = File.separator+"tmp";
        JFileChooser fc = new JFileChooser(new File(filename));
        // Show open dialog; this method does not return until the dialog is closed
        fc.showOpenDialog(frame);
        File selFile = fc.getSelectedFile();
        // Show save dialog; this method does not return until the dialog is closed
        fc.showSaveDialog(frame);
        selFile = fc.getSelectedFile();Here is a more elaborate example that creates two buttons that create and show file chooser dialogs.
        // This action creates and shows a modal open-file dialog.
        public class OpenFileAction extends AbstractAction {
            JFrame frame;
            JFileChooser chooser;
            OpenFileAction(JFrame frame, JFileChooser chooser) {
                super("Open...");
                this.chooser = chooser;
                this.frame = frame;
            public void actionPerformed(ActionEvent evt) {
                // Show dialog; this method does not return until dialog is closed
                chooser.showOpenDialog(frame);
                // Get the selected file
                File file = chooser.getSelectedFile();
        // This action creates and shows a modal save-file dialog.
        public class SaveFileAction extends AbstractAction {
            JFileChooser chooser;
            JFrame frame;
            SaveFileAction(JFrame frame, JFileChooser chooser) {
                super("Save As...");
                this.chooser = chooser;
                this.frame = frame;
            public void actionPerformed(ActionEvent evt) {
                // Show dialog; this method does not return until dialog is closed
                chooser.showSaveDialog(frame);
                // Get the selected file
                File file = chooser.getSelectedFile();
        };Here's some code that demonstrates the use of the actions:
        JFrame frame = new JFrame();
        // Create a file chooser
        String filename = File.separator+"tmp";
        JFileChooser fc = new JFileChooser(new File(filename));
        // Create the actions
        Action openAction = new OpenFileAction(frame, fc);
        Action saveAction = new SaveFileAction(frame, fc);
        // Create buttons for the actions
        JButton openButton = new JButton(openAction);
        JButton saveButton = new JButton(saveAction);
        // Add the buttons to the frame and show the frame
        frame.getContentPane().add(openButton, BorderLayout.NORTH);
        frame.getContentPane().add(saveButton, BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);

  • Opening a specific directory using JFileChooser.

    Iam using JFIleChooser to select a file is there any way that i the dialog opens at a particular directory say...c:\gallery\imagee...the default dialog opens @ MyDocuments Folder.

    Read the API documentation of the class, especially coustructor section.

  • Problem using JFileChooser

    Hi,
    I am encoutering a strange error dialog, javaw.exe No-Disk dialog box with this message "There is no disk in the drive. please insert a disk in drive A" when using JFileChooser.
    I have been referring to some forums and understood this is a bug. But most encountered this when they are using it with Java Web Service or some web application.
    I have Windows 2000 and mine is a java application. I have tried a workaround with WindowsAltFileSystemView but that does work with Windows 2000.
    So is there any workaround..help needed.
    thanks.

    If you do not do so already, try setting a starting point for your JFileChooser.
    JFileChooser chooser = new javax.swing.JFileChooser();
    chooser.setCurrentDirectory( someDirectory );The "someDirestory" could be any directory you want or need depending on Platform independance or not.
    regards,
    jarshe

  • Using JFileChooser to select directory only

    Hi. I am using JFileChooser to let the user to select the directory to save some files into the user-selected directory. I set the JFileChooser to show only directory and not files. Below show part of my code:
    private JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(true);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
         chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    int state = chooser.showDialog(frame, "Select Directory");
    if (state == JFileChooser.APPROVE_OPTION )
    file = chooser.getCurrentDirectory();
    However, the File reference that i get is not the user-selected directory. Please help.
    Thank you.

    Hi,
    i found that if user writes in the text field of save dialog name of the file(but application needs directory), getCurrentDirectory() returns correct directory. but if user chooses directory, getCurrentDirectory() returns parent directory but getSelectedFile() returns correct one, so i suggest something like this(it's nasty but it works [i hope;])
    JFileChooser dirChooser = new JFileChooser("");
    dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (dirChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
    java.io.File curDir = dirChooser.getSelectedFile().isDirectory()?dirChooser.getSelectedFile():dirChooser.getCurrentDirectory();

  • 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 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

  • Using  JFileChooser in JApplet

    Hi,
    I am using JFileChooser in JApplet to goto specific folder.
    But i am getting Access Denied error to that specific folder java.io.FilePermission error.
    Could you please help me how to solve this problem
    Thanks in advance.

    u need to make it a trusted applet. applets are not supposed to access ur disk information. they run in a separate space.
    read the trusted applets in java site's tutorial.
    ta,

  • 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 ...

  • File Extention when using JFileChooser

    I'm using the JFileChooser and a FileFilter with for extensions of .ses, and I can't get it to append .ses to a file name if the user doesn't do it at the time they are in the File choser.
    What I've tried:
    JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new SessionFileFilter());
    int retVal = fc.showSaveDialog(null);
    if(retVal == JFileChooser.APPROVE_OPTION){
         f = fc.getSelectedFile();
    if(!f.getName().endsWith(".ses")){
                   f=new File(f.getName()+".ses");
    ...SessionFileChooser...
    public boolean accept(File f) {
              boolean retval = false;
              int pos = f.getName().indexOf(".");
              if(pos != -1){
                   if(f.getName().substring(pos).equals(".ses")){
                        retval = true;
              return retval;
         public String getDescription() {
              return ".ses";
    ...any help would be appreciated, if you need source that compiles i'll get some worked out...
    to clarify the problem, if you go to save this web page and a dialog appears, you don't have to type .htm, but it automatically adds it before saving, this is what i'm trying to achieve.

    These two classes should do it. Let me know if there are any problems
    You are welcome to use and modify this code, but please don't change the package or take credit for it as your own work
    FileExtensionFilter
    ===============
    package tjacobs.ui.fc;
    import java.io.File;
    import javax.swing.filechooser.FileFilter;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    public class FileExtensionFilter extends FileFilter {
        private ArrayList<String> mExtensionList;
        private String mDesc;
        public FileExtensionFilter (String extension) {
            mExtensionList = new ArrayList<String>(1);
            mExtensionList.add(extension);
        public FileExtensionFilter(List<String> extensions) {
            mExtensionList = new ArrayList();
              mExtensionList.addAll(extensions);
        public FileExtensionFilter(String[] extensions) {
            mExtensionList = new ArrayList();
            for (int i =0; i < extensions.length; i++) {
                mExtensionList.add(extensions);
         public void addExtension(String extension) {
              mExtensionList.add(extension);
         public Iterator<String> getExtensions() {
              Iterator<String> i = Collections.unmodifiableList(mExtensionList).iterator();
              return i;
    public boolean accept(File file) {
         if (file.isDirectory()) {
              return true;
    String name = file.getName();
    int idx = name.indexOf(".");
    String type = "";
    if (idx != -1) {
    type = name.substring(idx + 1);
    type = type.toLowerCase();
    return mExtensionList.contains(type);
    public void setDescription(String desc) {
    mDesc = desc;
    public String getDescription() {
    if (mDesc == null) {
    mDesc = "";
    for (int i = 0; i < mExtensionList.size(); i++) {
    mDesc += (i != 0 ? ", " : "") + "." + mExtensionList.get(0).toString();
    mDesc+= " files";
    return mDesc;
    public String getType () {
    return mExtensionList.get(0).toString();
    public static class HTMLFilter extends FileExtensionFilter {
    public HTMLFilter () {
    super(new String[] {"html", "htm"});
    setDescription("Web Page Files");
    public static class RTFFilter extends FileExtensionFilter {
    public RTFFilter () {
    super("rtf");
    setDescription("Rich Text Format Files");
    public static class TextFilter extends FileExtensionFilter {
    public static final String TYPES[] = new String[] {"txt", "text", "java"};
         public TextFilter () {
    super(TYPES);
    setDescription("Text Files");
    FileChooser
    ==========
    * Created on Jun 22, 2005 by @author Tom Jacobs
    package tjacobs.ui.fc;
    import java.awt.Component;
    import java.io.File;
    import java.util.List;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileSystemView;
    public class FileChooser extends JFileChooser {
         public FileChooser(FileExtensionFilter filter) {
              super();
              addChoosableFileFilter(filter);
         public FileChooser(String type) {
              this (new FileExtensionFilter(type));
         public FileChooser(List<String> types) {
              this (new FileExtensionFilter(types));
         public FileChooser(String path, FileExtensionFilter filter) {
              super(path);
              addChoosableFileFilter(filter);
              // TODO Auto-generated constructor stub
         public FileChooser(String path, String type) {
              this(path, new FileExtensionFilter(type));
              // TODO Auto-generated constructor stub
         public FileChooser(String path, List<String> types) {
              this(path, new FileExtensionFilter(types));
              // TODO Auto-generated constructor stub
         public FileChooser(File path, FileExtensionFilter filter) {
              super(path);
              addChoosableFileFilter(filter);
         public FileChooser(File path, String type) {
              this(path, new FileExtensionFilter(type));
              // TODO Auto-generated constructor stub
         public FileChooser(File path, List<String> types) {
              this(path, new FileExtensionFilter(types));
              // TODO Auto-generated constructor stub
         public FileChooser(FileSystemView arg0, FileExtensionFilter filter) {
              super(arg0);
              addChoosableFileFilter(filter);
         public FileChooser(FileSystemView arg0, String type) {
              this(arg0, new FileExtensionFilter(type));
              // TODO Auto-generated constructor stub
         public FileChooser(FileSystemView arg0, List<String> types) {
              this(arg0, new FileExtensionFilter(types));
              // TODO Auto-generated constructor stub
         public FileChooser(File path, FileSystemView arg1, FileExtensionFilter filter) {
              super(path, arg1);
              addChoosableFileFilter(filter);
         public FileChooser(File path, FileSystemView arg1, String type) {
              this(path, arg1, new FileExtensionFilter(type));
                        // TODO Auto-generated constructor stub
         public FileChooser(File path, FileSystemView arg1, List<String> types) {
              this(path, arg1, new FileExtensionFilter(types));
              // TODO Auto-generated constructor stub
         public FileChooser(String path, FileSystemView arg1, FileExtensionFilter filter) {
              super(path, arg1);
              addChoosableFileFilter(filter);
              // TODO Auto-generated constructor stub
         public FileChooser(String path, FileSystemView arg1, String type) {
              this(path, arg1, new FileExtensionFilter(type));
              // TODO Auto-generated constructor stub
         public FileChooser(String path, FileSystemView arg1, List<String> types) {
              this(path, arg1, new FileExtensionFilter(types));
              // TODO Auto-generated constructor stub
         public int showSaveDialog(Component c) {
              int ok = super.showSaveDialog(c);
              if (ok == JFileChooser.APPROVE_OPTION) {
                   FileFilter filter = getFileFilter();
                   if (filter instanceof FileExtensionFilter) {
                        File f = getSelectedFile();
                        if (!filter.accept(f)) {
                             setSelectedFile(new File(f.getAbsolutePath() + "." + ((FileExtensionFilter)filter).getType()));
              return ok;

Maybe you are looking for

  • ITunes Freezes on Shutdown - "Program Not Responding" error

    Hi, newbie here. Running Windows XP and iTunes 7.7 When I try to close iTunes it just freezes and I have to use the Windows Task Manager to quit the program. What is the fix for this ? Any help appreciated.

  • Help required in XSLT

    Dear Experts , I want to convert my XML file to the ABAP Internal table. For this I have to Setuo a XSLT transformation. My XML File is as follows : <!--XML Export from Broadcast Master List.--> <!--Seg Codes List, Created 02/02/2010 16:02--> <?xml v

  • ERROR: p2v module S40_setup_preload failed: 0

    Hi, I get "ERROR: p2v module S40_setup_preload failed: 0" during installation of Solaris 8 zone. However, system seems to be running. After zlogin, /var/adm/utmpx was missing. [NOTICE: Zone rebooting] SunOS Release 5.8 Version Generic_Virtual 64-bit

  • UTL_SMTP mail with attachment( Problem in attaching zip file)

    Hi All, I used the below code for sending email with attachment. but when i try to add the message body its not working in the sense its not attaching my file. when i commented that line its attaching the file. commented lines: -- utl_smtp.write_data

  • Lightroom 3 wiping all my presets

    I purchased Lightroom 3 as a download last year, and I've had constant issues with it ever since. Problems include the following: -On startup, it says my camera profiles are missing, and to reinstall Lightroom to fix the issue. Of course, reinstallin