JFileChooser and File.renameTo()

Hi,
Anyone experienced strange behaviour from the JFileChooser returned
File Object. In my case it's an instance of:
sun.awt.shell.Win32ShellFolder2
Unfortunatly the File.renameTo(File file) method doesn't work
properly with this File instance.
Anyhelp is welcome / dzone

overwrite the approveSelection() method of your JFileChooser. in there you can do your checks before executing super.approveSelection().
tthomas

Similar Messages

  • JFileChooser and file validation

    Hi,
    I use JFileChooser.showSaveDialog(). I neen when user clicks the "Save" button to check if the file already exists and if so to show him warning message and eventually break the approve operation.

    overwrite the approveSelection() method of your JFileChooser. in there you can do your checks before executing super.approveSelection().
    tthomas

  • Make "File name" and "Files of type" fields read-only in JFileChooser

    I try to make the "File name" and "Files of type" fields read-only in JFileChooser dialog. Anybody
    knows how to do? Thanks.

    You mean so the user can't choose the name of the file to open or save? Not much point in even using a JFileChooser, then, is there? Or did I misunderstand the question?

  • File.renameTo() and locking

    Hi,
    I would like to rename file, but File.renameTo() will not work if the file will be locked by some other process. If other process has locked the file, I would like to wait for it to release the lock. So I have:
    FileLock lock = new RandomAccessFile(file, "rw").getChannel().lock(0L, Long.MAX_VALUE, false);
    file.renameTo(destFile);
    lock.release();But this does not work, because file is locked and renameTo does not work (returns false).
    What can I do to lock the file myself (wait for other locks to be released) and to rename it (rename does not work when file is locked).
    Regards
    Pawel Stawicki

    hi, I don't thik you have to lock the file yourself while renaming it because that is (from my point of view) an opperating system's job to do it.
    you could maybe make a
    while(! file.renameTo()){
    thread.sleep(1000);
    to wait till its unlocked.
    I'm not sure that helps but that's just an idea

  • JFileChooser and remote filesystems

    I want to add(among local file system) a few remote filesystems to JFileChooser ,
    I implemented FileSytestemVIew(FileSystem) and File(RemoteFile) class.
    At the first glance everything looks ok - i can see local folders and remote root folder(in combo box), when i choose remote root i can see remote folders and files, but when i invoke double click to enter remote folders, exception occurs.
    for some reason JFileChooser sees 'ordinary' File - not my RemoteFile, and it treats it as a file (not folder) and wants to open it (approveSelection fires)
    Probably i did not implemented all the methods that are used ..
    Any ideas ? maybe there are some other ways to explore remote filesystems ?
    package pl.edu.pw.browser;
    import javax.swing.filechooser.FileSystemView;
    import java.io.File;
    import java.io.IOException;
    import pl.edu.pw.fileserver.client.Client;
    import java.util.*;
    import javax.swing.Icon;
    public class FileSystem extends FileSystemView {
    public FileSystem(ArrayList servers) {
    this.servers=servers;
    public File createFileObject(File dir, String filename) {
    System.out.println("createFileObject1");
    if (dir instanceof RemoteFile )
    return new RemoteFile(((RemoteFile)dir).getFtp(),dir.getAbsolutePath(), filename);
    return super.createFileObject(dir,filename);
    public boolean isDrive(File dir)
    if (dir instanceof RemoteFile )
    return false;
    return super.isDrive(dir);
    public boolean isFloppyDrive(File dir)
    if (dir instanceof RemoteFile )
    return false;
    return super.isFloppyDrive(dir);
    public boolean isComputerNode(File dir)
    if (dir instanceof RemoteFile)
    if(servers.contains(dir))
    return true;
    else
    return false;
    return super.isComputerNode(dir);
    public File createFileObject(String path) {
    return null;
    public boolean isFileSystem(File f) {
    System.out.println("isFileSystem");
    if (f instanceof RemoteFile) {
    return false;
    } else
    return super.isFileSystem(f);
    public boolean isFileSystemRoot(File dir)
    System.out.println("isFileSystemRoot");
    if (dir instanceof RemoteFile)
    if(servers.contains(dir))
    return true;
    else
    return false;
    return super.isFileSystemRoot(dir);
    public boolean isRoot(File f) {
    System.out.println("isRoot");
    if (f instanceof RemoteFile )
    if(servers.contains(f))
    return true;
    else
    return false;
    return super.isRoot(f);
    public String getSystemTypeDescription(File f)
    if (f instanceof RemoteFile)
    return f.getName();
    return super.getSystemTypeDescription(f);
    public Icon getSystemIcon(File f)
    return super.getSystemIcon(f);
    public boolean isParent(File folder,
    File file)
    if (folder instanceof RemoteFile && file instanceof RemoteFile )
    System.out.println("isParent("+folder.getAbsolutePath()+")("+file.getAbsolutePath()+")");
    if(file.getParent().equals(folder.getAbsolutePath()))
    System.out.println("is");
    return true;
    else
    return false;
    return super.isParent(folder,file);
    public File getChild(File parent,
    String fileName)
    System.out.println("getChild");
    if (parent instanceof RemoteFile )
    return new RemoteFile(((RemoteFile)parent).getFtp(),parent.getAbsolutePath(),fileName);
    return super.getChild(parent,fileName);
    public File createNewFolder(File containingDir)
    throws IOException {
    System.out.println("createNewFolder");
    if (containingDir instanceof RemoteFile )
    return null;
    return new File(containingDir,"/nowyFolder");
    public String getSystemDisplayName(File f)
    if (f instanceof RemoteFile )
    return f.getName();
    else
    return super.getSystemDisplayName(f);
    public File[] getRoots()
    System.out.println("getRoots");
    File[] files = super.getRoots();
    File[] fileAll = new File[files.length+1];
    int i=0;
    for(i=0;i<files.length;i++)
    fileAll=files[i];
    fileAll[i]=createFileSystemRoot((RemoteFile)servers.get(0));
    return fileAll;
    public boolean isHiddenFile(File f) {
    return f.isHidden();
    public File getParentDirectory(File dir) {
    System.out.println("getParentDirectory");
    if (dir instanceof RemoteFile)
    String p = dir.getParent();
    if(p!=null)
    return new RemoteFile(((RemoteFile)dir).getFtp(),p);
    else
    return null;
    else
    return super.getParentDirectory(dir);
    protected File createFileSystemRoot(File f)
    System.out.println("createFileSystemRoot");
    if (f instanceof RemoteFile)
    return new FileSystemRoot( (RemoteFile) f);
    else
    return super.createFileSystemRoot(f);
    static class FileSystemRoot extends RemoteFile {
    public FileSystemRoot(RemoteFile f) {
    super(f.getFtp(),f.getAbsolutePath());
    public File[] getFiles(File dir, boolean useFileHiding) {
    if (dir instanceof RemoteFile)
    RemoteFile[] files = (RemoteFile[])( (RemoteFile) dir).listFiles();
    return files;
    else
    return dir.listFiles();
    public File getHomeDirectory() {
    return super.getHomeDirectory();
    ArrayList servers = null;
    package pl.edu.pw.browser;
    import java.io.File;
    import java.io.FilenameFilter;
    import java.io.FileFilter;
    import pl.edu.pw.fileserver.client.Client;
    import java.util.*;
    import java.text.*;
    import pl.edu.pw.fileserver.Constants;
    public class RemoteFile extends File {
    final static char PATHDELIMS = '/';
    public final static String absoluteStart = "//";
    public RemoteFile(Client ftp, String parent) {
    super(parent);
    this.ftp = ftp;
    path = parent;
    public RemoteFile(Client ftp, String parent, String name) {
    this(ftp, parent);
    if (path.length()>0 && path.charAt(path.length()-1) == PATHDELIMS)
    path += name;
    else
    path += PATHDELIMS + name;
    public boolean equals(Object obj) {
    if (!checked)
    exists();
    return path.equals(obj.toString());
    public boolean isDirectory() {
    if (!checked)
    exists();
    return isdirectory;
    public boolean isFile() {
    if (!checked)
    exists();
    return isfile;
    public boolean isAbsolute() {
    if (!checked)
    exists();
    return path.length() > 0 && path.startsWith(this.absoluteStart);
    public boolean isHidden() {
    if (!checked)
    exists();
    return ishidden;
    public long lastModified() {
    return modified;
    public long length() {
    return length;
    public String[] list() {
    return list(null);
    public String[] list(FilenameFilter filter) {
    System.out.println("list");
    String[] result = null;
    try{
    ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
    ArrayList files = new ArrayList();
    for(int i=0;i<names.size();i++)
    RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
    if (filter == null || filter.accept(this,rf.getName()))
    files.add(rf.getName());
    result = new String[files.size()];
    files.toArray(result);
    catch(Exception ex)
    ex.printStackTrace();
    return result;
    public File[] listFiles() {
    FileFilter filter = null;
    return listFiles(filter);
    public File[] listFiles(FileFilter filter) {
    System.out.println("listFiles");
    RemoteFile[] result = null;
    try{
    ArrayList names = (ArrayList)ftp.dir(this.getAbsolutePath());
    ArrayList files = new ArrayList();
    for(int i=0;i<names.size();i++)
    RemoteFile rf = new RemoteFile(ftp,(String)names.get(i));
    rf.exists();
    if (filter == null || filter.accept(rf))
    files.add(rf);
    result = new RemoteFile[files.size()];
    System.out.println("listFiles.size="+files.size());
    files.toArray(result);
    catch(Exception ex)
    ex.printStackTrace();
    return result;
    public String getPath() {
    return path;
    public String getCanonicalPath() {
    return getAbsolutePath();
    public String getAbsolutePath() {
    if (!isAbsolute()) {
    return ftp.pwd();
    return path;
    public String getName() {
    String result=path;
    if(result.charAt(result.length()-1) == this.PATHDELIMS)
    result = result.substring(0,result.length()-1);
    int i = result.lastIndexOf(this.PATHDELIMS);
    if(i!=-1)
    result = result.substring(i+1);
    return result;
    public String getParent() {
    String result=path;
    if(result.charAt(result.length()-1) == this.PATHDELIMS)
    result = result.substring(0,result.length()-1);
    int i = result.lastIndexOf(this.PATHDELIMS);
    if(i<3)
    return null;
    result = result.substring(0,i);
    return result;
    public boolean exists() {
    boolean ok = false;
    try {
    String r = ftp.exists(path);
    if(r != null)
    System.out.println("('"+path+"')header:"+r);
    ok = true;
    StringTokenizer st = new StringTokenizer(r,Constants.HEADER_SEPARATOR);
    String answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    isfile=true;
    isdirectory=false;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    canread = true;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    canwrite = true;
    answer = st.nextToken();
    if(answer.equals(Constants.TRUE))
    ishidden = true;
    answer = st.nextToken();
    length = Long.parseLong(answer);
    if(isfile)
    answer = st.nextToken();
    modified = Long.parseLong(answer);
    checked = true;
    catch (Exception ex) {
    ex.printStackTrace();
    return ok;
    public boolean canRead() {
    return canread;
    public boolean canWrite() {
    return canwrite;
    public int hashCode() {
    return path.hashCode() ^ 098123;
    public boolean mkdir() {
    return false;
    public boolean renameTo(File dest) {
    return false;
    public Client getFtp() {
    return ftp;
    private Client ftp;
    private boolean checked = false;
    private boolean isdirectory = true;
    private boolean isfile = false;
    private boolean ishidden = false;
    private boolean canread = false;
    private boolean canwrite = false;
    private String path;
    private long length = 0;
    private long modified =0;
    java.lang.NullPointerException
         at pl.edu.pw.browser.Browser.openLocalFile(Browser.java:136)
         at pl.edu.pw.browser.component.FileChooser.approveSelection(FileChooser.java:31)
         at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
         at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
         at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:207)
         at java.awt.Component.processMouseEvent(Component.java:5137)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    i solve the problem .
    I did not overwrite File.getConicalFile() , this method is invoked at javax.swing.plaf.basic.BasicFileChooserUI$DoubleClickListener.mouseClicked(BasicFileChooserUI.java:412)
    that is why i recived a new object type File when I was waiting for RemoteFile

  • Concurrent processing & file.renameTo(...)

    Hi,
    I've can successfully move a file in the single thread/process environment using file.renameTo
    However in the multithreaded/multiple process environment, the initial file is several MB (about 100mb). It is created on the fly outside of my thread and takes several minutes to build.
    I would like to rename it after the file is finished building.
    In my code I do the following:
    boolean success = false;
    while (! success)
    success = inputFile.renameTo(dest);
    QuickSleep(1500); // Performs a Thread.sleep in a try/catch
    I've seen some weird behavior however. On a windows box the renameTo seems to return false if the other process is still writing to the file. However on linux the .renameTo is returning true even though the file hasn't finished building.
    The end result on linux is I end up with two files. One that got renamed and is partially filled and the other original with the rest of the file.
    Is there a way to know when the file isn't being written by another process/thread?
    Thanks in advance.

    if by now you still have the problem (FYI this is working on AIX) have a look at my solution:
    for (int i = 0; i < dir.listFiles().length; i++) {
    try {
         Process p = Runtime.getRuntime().exec("/usr/sbin/fuser " + dir.listFiles().getAbsolutePath());
         p.waitFor();                              
         InputStream in = p.getInputStream(); // we have to read the stream to verify if there is a process id
         int c = in.read();
         String stream = "";
         while (c != -1) {
              stream = stream + (char)c;
              c = in.read();
         if (stream.trim().length() > 0) {
              logger.info("File: " + dir.listFiles()[i] + " is in use by process ID:" + stream);
              try {
                   Thread.sleep(5000); //sleep for 5 sec
              } catch (InterruptedException e){
                   // the VM doesn't want us to sleep anymore,
                   // so get back to work
              continue;
    } catch (Exception e) {
         logger.error("fuser exception: " + e.getMessage());

  • Java.io.File renameTo does not work on Solaris

    Hi Experts,
    I have a code-piece which tries to move files from one directory to another on the SAME FILE SYSTEM using java.io.File.renameTo method.
    It works fine when there less no. of files in the source directory. But the renameTo does not work as expected when there are very huge no. of files(~40K) present in the source directory.
    I am aware that there is a known issue when one tries to use this method to move files across file systems OR if the file exists at the destination directory.
    But in my case the file system is the same and the there is no such file in the destination directory.
    I suspect some inode related issues. But not sure what it is exactly.
    Is there any limitations of renameTo?
    Please help.

    OK, we all now understand you have a problem in doing this, but without the specifics of the problem that you are experiencing, then it is fairly difficult to give you anything other than a guess. If you would like some specific and relevent answers, please supply specifics about how exactly the operation differs from your expected results. You should also post example code as it is almost always asked for eventually.

  • File.renameTo(File) doesn't change dirs on Linux?!

    Hi All,
    I'm trying to change a file's name and directory with File.renameTo but it doesn't work. It says in the manual that changing dirs is O/S dependent, so i guess it doesn't work on Linux.
    Is it correct? if so, what can be done to change a file's name and directory?
    File oldFile = new File(filePath);
    oldFile.delete();   // Delete old file
    File newFile = new File(newFilePath);     // This is the new file
    File tempFile = new File(filePath);          // Get name to renameTo
    newFile.renameTo(tempFile)                  // Try to rename

    Hmm, it worked for me, though I didn't try deleting the oldFile. A simple move from one directory to another was not problem, though. The rename would fail if the delete failed. You might check that.

  • JFileChooser and My network Places??

    Hello all,
    In the Filename of JFileChooser if i type \\100.100.100.100 or even \\100.100.100.100\d$ and click on open button it should ask the username and password of that pc and on appropriate combination of username and password it should show the list of the folder and file of that PC.
    How to get this?what is the code that is to be written in the open button event?
    Thank you,
    Ramesh shrestha

    I am running XP home with SP3.  click on start then my network place.  You should see different folders from your other computers and your router.  On the left  it should show either show or hide icons for network upnp.  If you are seeing the icons for lan and wireless and gateway then your computer settings are not setup properly.
    Right-click on start then click on properties  Click on customise then advance.  Go down to Network Connections set settings to display as connect to menu.
    Greetings from Northern Ontario, Canada

  • File.renameTo

    Hi,
    Does file.renameTo work on AIX Server,and how much time will this method take to move a file of 35 million records?
    Regards
    KK

    NAME
    rename - rename a file
    SYNOPSIS
       #include <stdio.h>
        int rename(const char old, const char new);
    DESCRIPTION
    The rename() function changes the name of a file.
    The old argument points to the pathname of the file to be renamed.
    The new argument points to the new pathname of the file.
    posman@proli:~/ivan> df -k . /tmp
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cciss/c0d0p3     16682556  14755300   1927256  89% /home
    /dev/cciss/c0d1p2     35539772  33619432   1920340  95% /
    posman@proli:~/ivan> cat x.c
    #include <stdio.h>
    int main() {
    int r =  rename("movethis","/tmp");
    if (r !=0) perror("rename");
    return r;
    }posman@proli:~/ivan> gcc x.c -o x
    posman@proli:~/ivan> ./x
    rename: Invalid cross-device link
    Edited by: BIJ001 on Oct 1, 2007 9:01 AM

  • File.renameTo() bugg? Leaves the file open

    I came across the strangest behaviour of File.renameTo() for the following steps:
    1. Rename a file - successful
    2. Rename the same file again - will fail. Also delete will fail.
    -------- some code ----------
    File file=new File("F1");//nonexistent file
    //write some to the file - just to make the file to be created
    RandomAccessFile rFile=new RandomAccessFile(file,"rw");
    rFile.writeBytes("Hello");
    rFile.close();
    //A successful rename
    boolean renamed=file.renameTo(new File("F2"));
    System.out.println("renamed="+renamed);
    //This is commented code for now
    //rFile=new RandomAccessFile(file,"rw");
    //rFile.close();
    //This rename fails!
    renamed=file.renameTo(new File("F3"));
    System.out.println("renamed again="+renamed);
    As it seems File.renameTo() sets the file to open, since neither renameTo or delete will work after a renameTo.
    BUT, if I uncomment the commented code, it will work again! I just open a dummy RandomAccessFile (FileInputStream would work as well I guess) and then close it, and somehow the file is set to closed again, and the second renameTo() will work.
    Is this a bugg in File.renameTo()? I run on windows XP and have java 1.4.1_02-b06. I couldn't find any comment about this in the Bug Database.
    Gil

    Aha! so the reason why the opening of the dummy RandomAccessFile did it in my previous code, was becase it created the old File "F1" again that could be renamed again. So the correct code should instead be:
    -------- some code ----------
    File file=new File("F1");//nonexistent file
    //write some to the file - just to make the file to be created
    RandomAccessFile rFile=new RandomAccessFile(file,"rw");
    rFile.writeBytes("Hello");
    rFile.close();
    //A successful rename
    File file2=new File("F2");
    boolean renamed=file.renameTo(file2);
    System.out.println("renamed="+renamed);
    //Now this rename also succeeds!
    renamed=file2.renameTo(new File("F3"));//do rename on file2!
    System.out.println("renamed again="+renamed);
    Gil

  • JFileChooser and FileFilters

    I have the following problem:;
    I have a JFileChooser and I attached a FileFilter to it, which only allows files with the extension *.in and *.inx. Everything works well - only files with these extensions are shown in the Dialog.
    But as a user I expect, that it is not a fault if I only type in the name of the file, because I expect the programme to add the extension automatically. For example in an OpenDialog, the user sees the file test.inx and the types in "test", because he/she thinks that the extension will be added.
    This is not the case...and which is even worse, the call of fileChooser.getSelectedFiles() will return an empty array. Hence there is no possibility for the programme to add the file extension.....
    How can solve this problem?? What is my mistake?? I cannot image that Swing is not able to do this, because this common FileDialog behaviour....
    I thank everybody who tries to help me...

    The quick and dirty workaround would be to create a "Save" dialog (setDialogType method), set the Button texts to whatever you want, the same for title. When the dialog returns, you can check the file (getSelectedFile()), and if it does not exist, try the same name with the extension(s).

  • JFileChooser and thumbnail view

    How can I implement a custom JFileChooser that show thumbnail of image files such as TIFF and PNG?
    As before, I used FileDialog on Windows XP for this purpose.
    But FileDialog does not support multi file selection and file name filters.
    I tried to implement custom FileView. (getIcon() method).
    But it was so slow and strange.
    Could you guys give me a advice on this problem?

    Hi Dhiva,
    materialized view is essentially a table that is produced from other tables based on a query. It's results are physically stored in the database and are refreshed either when the user requests ('on-demand refresh') or after commit.
    A simple view is just a query stored in the database. It's results are not stored anywhere, they're calculated and returned to the user only when the view is queried.
    Best regards,
    Nikolay

  • File.renameTo method issue

    I have a Java program which processes upto 10000 text files a day. The average size of these files are 1KB to 2KB and the java program parses the contents of the text file, validates and loads them into a database table.
    The program outline is as follows
    File[] filesToProcess = sourceFolder.listFiles();
    int fileCount = filesToProcess.length;
    for (int i=0;i<fileCount;i++) {
    File currentFile = filesToProcess;
    MsgParser fileParser = new MsgParser(currentFile);
    if ( fileParser.isMessageValid()) {
    boolean uploadSuccess = fileParser.uploadToDB();
    if (uploadSuccess) {
    if (currentFile.renameTo(parseSuccessArchiveFile))
    logger.info("File successfully moved to archive folder);
    else
    logger.info("File cannot be moved to archive folder);
    } else {
    if (currentFile.renameTo(parseFailureArchiveFile)
    logger.info("Parser failed file moved to archive folder);
    else
    logger.info("Parser failed file cannot be moved to archive folder);
    The above program outline works well. However the renameTo method is not renaming the parsed files successfully on all occasions. There is no performance issue involved here as the files keep streaming in throughout the day and the program is able to handle the parsing of the file(s) in a fraction of second.
    The issue for me is that I keep picking the files to parse from the source folder at regular intervals ( after a full iteration of the files list, wait for 10 seconds before calling for a new set of files ) and cannot afford to have a failure in moving the file to the archive folder as otherwise, I end up parsing the same file multiple number of times, which I want to avoid.
    Can anyone shed some light on the behavior of File.renameTo and how to make it work successfully?
    Sundar

    I am making the code more readable for you all and corrected some typo errors...
    File[] filesToProcess = sourceFolder.listFiles();
    int fileCount = filesToProcess.length;
    for (int i=0;i<fileCount;i++) {
          File currentFile = filesToProcess;
          MsgParser fileParser = new MsgParser(currentFile);
          boolean uploadSuccess = false;
          if ( fileParser.isMessageValid())
               uploadSuccess = fileParser.uploadToDB();
          if (uploadSuccess) {
                if (currentFile.renameTo(parseSuccessArchiveFile))
                      logger.info("File successfully moved to archive folder);
                else
                      logger.info("File cannot be moved to archive folder);
          } else {
                if (currentFile.renameTo(parseFailureArchiveFile)
                      logger.info("Parser failed file moved to archive folder);
                else
                      logger.
                      info("Parser failed file cannot be moved to archive folder);
    }

  • JFileChooser selected file

    from my code below, the File Name in the dialog/file selection window defaults to the file but once I click on to a directory to change directory the File Name changed to the directory name. How do I set the filechooser to not change the File Name if a directory is clicked? Thanks, jude
    File fileSelected = new File("c:\\temp\\newfile.txt");
    JFileChooser filechooser = new JFileChooser();
    filechooser.setDialogTitle("Save to a text file.");
    filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    filechooser.setSelectedFile(fileSelected);
    int iStatus = filechooser.showOpenDialog(null);
    if (iStatus == JFileChooser.APPROVE_OPTION) {
         fileSelected = filechooser.getSelectedFile();
    else if (iStatus == JFileChooser.CANCEL_OPTION) {
         return;
    ...

    I have been able to get the JFileChooser to behave in a more standard way when the user uses the mouse to select files. I have still not been able to find a way to get it to work the way I want if they've typed a file in manually. Does anyone know how to get to the JTextField in the JFileChooser to read the value?
    If anyone could hook me up with how to access the JTextField I'd sure be greatful!!!
    Here is how I 'fixed' the traversal of folders using the mouse.
    I subclassed the JFileChooser and made a local variable
    private File lastSelectedFile = null;
    I then registered property changed listeners in the constructor for both file selection and directory changes:
    this.addPropertyChangeListener(JFileChooser.DIRECTORY_CHANGED_PROPERTY,
    (new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
    processDirChanged(e);
    this.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY,
    (new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent e) {
    processFileSelected(e);
    Here are the propertyChangedListeners:
    public void processDirChanged(PropertyChangeEvent e) {
    if ( lastSelectedFile != null ) {
    File newSelectedFile = new File(this.getCurrentDirectory().getPath() + File.separator + this.lastSelectedFile.getName());
    this.lastSelectedFile = newSelectedFile;
    this.setSelectedFile(this.lastSelectedFile);
    public void processFileSelected(PropertyChangeEvent e) {
    File selectedFile = this.getSelectedFile();
    if ( lastSelectedFile != null && ( selectedFile == null || selectedFile.isDirectory()) ) {
    this.setSelectedFile(this.lastSelectedFile);
    else {
    lastSelectedFile = this.getSelectedFile();
    }

Maybe you are looking for

  • Boot Camp Mac Pro Vista 32 / 64 Nvidia 7300GT Maya / OpenGL apps freeze?

    I have successfully installed Vista 32 and 64 in addition to OSX. I have the latest BootCamp install. (which should not matter) I have installed the latest Nvidia drivers for the 7300GT in both 32 and 64. Whenever I try and launch any openGL applicat

  • Cursor won't stay in Title or Comments field

    I am using iPhoto 4.0.3. When I click in the title or comments field, the cursor always goes away and I can't type in the field any more. It used to be that if I clicked in the field a second time, the cursor would stay and I could type. Now, it will

  • WebDynpro Abap code to read IView Name

    Hi Friends, Could you please give me Webdynpro abap code to read the name of the Iview. Regards, Lakshmi Prasad.

  • New Laptop-Importing iPhoto issues

    I have a new MacBook Pro with iPhoto 08 (v7.1) on it. I want to import my images from my old Powerbook G4 (which is running the previous version of iPhoto). I tried connecting the old laptop in firewire mode and just importing the entire iPhoto folde

  • Not include digital booklets in smart playlists?

    I don't know if there's any way to do this, but I have smart playlists created, which are based on certain genres, or only include certain artists - but they always include the digital booklets from these artists, and I can't just get rid of the digi