JFileChooser Replacing File Name

I am using a JFileChooser as a "Save" dialog box. Here is the situation: the user has entered a proposed file name, then he/she double clicks on a directory where the file should be saved. Then they click "Save". At the point the user double clicked the directory, his/her proposed file name has been replaced by the directory name. The user may not notice it before he/she clicks "Save" thus creating a file in the directory with the same name as the directory.
This "proposed file name replacing" behavior is fine when the user clicks a file but shouldn't happen when a directory is selected. The common Windows filechooser gets this right.
Is it possible to make JFileChooser stop doing this?
Thanks!

When you doubleclick, you have to check wether the selection is a file or a directory with the isDirectory() method. You can than decide to overwrite the Stringvalue or not, depending on the case.
KR,
Jan

Similar Messages

  • Problems with replace file name with starting and ending Bates number

    When applying Bates numbers to a set of Acrobat pdf files I am unable to replace file names with the starting and ending Bates number. This is important
    for me in a legal application.
    The Bates numbers are applied to each page of each of file without any problem as required.
    The Bates log file indicates that the files have been renamed as I wanted.
    I am running Adobe Acrobat Professional 9 with the update to 9.1.9 and Windows XP Service Pack 3 (the last or current service pack)
    In all other respects Adobe Acrobat 9 is running to my satisfaction.
    Has anyone else had this problem and found a solution?
    HRKExon

    Thanks for asking the question, I hadn't heard of Bates numbers before and this gave me a chance to look up something new.
    When I googled for ' bates number legal index ' I found this document:
    http://www.adobe.com/devnet/acrobat/pdfs/batesnumbering9.pdf
    Maybe that will help.
    Scott Bonacker CPA
    Springfield, MO

  • Replace File Name of Path

    EDIT:
    I am trying to build a string array into a path, however it ends up not being formatted correctly.  Perhaps this is a "scan code" issue with the backslashes?
    Is there a better/correct way to do this?  I want to just change the file name of an already existing path.
    For example:
    c:\Desktop\Folder\File1.csv
    becomes
    c:\Desktop\Folder\FileName.csv
    My "Spreadsheet String" is just a Path to String of an existing file path in the same destination folder. 
    I break the old path (in string form) into an array seperated by the slash.  Then I replace the last array element (the file name).  Then I make it an array again and convert it to a path.  Although it looks correct, LabVIEW throws an error with this path saying it does not exist.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!
    Solved!
    Go to Solution.

    Ah, yes!  Thank you!  The Strip File Path function did exactly what I needed in a very robust way.  I cannot believe I had never come across that function before.  It would have saved me much struggling
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • JFileChooser file name extention queistion

    hi i would like to know if it is possible to place a file extention in the filename section when you open the save dialog. So as when the user types a file name in the file extention is added automaticly to only allow the user to save in .png. My code is as follows.
    private void screenshot()
              /** currently no dialog to confirm action as remains
              on screen when saving screenshot! **/
              int status;
              JFileChooser fc = new JFileChooser();
              fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
              try {
                        Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit ().getScreenSize ());
                        BufferedImage image = new Robot().createScreenCapture(rect);
                        try {
                             fc.addChoosableFileFilter(new PNGFilter());
                            status = fc.showSaveDialog(information);
                            if(status == JFileChooser.APPROVE_OPTION)
                            File selFile = fc.getSelectedFile();
                            ImageIO.write(image, "png", selFile);
                            JOptionPane.showMessageDialog(information, "File saved to "+ selFile);     
                        } catch (IOException e) {
                                  Error.SaveError(e);
                        catch (AWTException e) {
                             Error.AbstractWindowToolkit(e);
    }

    You can always check selFile's name, and if it
    doesn't end with .png replace it
    with a new File with the same name, but with .png
    added on.Thanks for that. I have done just that and it works great now.
    if(getExtension(selFile).equals("NO_EXTENSION"))
                               selFile = new File(selFile.toString() + ".png");
                           }

  • [SOLVED] Find and replace quotes with underscores in file names

    I was looking to replace all of the quotes in file names in a directory with underscores.  I seem to be having a problem doing so, though.  Running the find command:
    find . -name '*[\`\'\"]*' -exec sh -c "mv -i '$0' '${0//[\`\'\"]/_}'" {} \;
    I get a > inviting me to continue the command.  What am I doing wrong?
    Last edited by gogi-goji (2010-01-03 02:19:13)

    @lolilolicon: yeah the -exec part does give another level of quotes, so you can run into trouble with scripts inside -exec.
    I didn't know you could give {} as an argument after sh -c and $0, that solves the problem of not knowing which quotes to use around it in the -exec part.
    $ find -mindepth 1 -exec sh -c 'mv -v --backup=t "$0" "$(echo "$0" | sed s/[\\x27\"\`]/___/g)"' {} \;
    mv: `./a b' and `./a b' are the same file
    `./\'' -> `./___'
    `./\'"\'' -> `./_________'
    mv: `./$0' and `./$0' are the same file
    mv: `./a' and `./a' are the same file
    mv: `./$(echo crash)' and `./$(echo crash)' are the same file
    `./"' -> `./___' (backup: `./___.~1~')
    `./\'\'\'' -> `./_________' (backup: `./_________.~1~')
    Or with the other substitution method, it doesn't interpret \x27 (you could use $(echo -e \\x27) or you have to use ...'\\\''...
    $ find -mindepth 1 -exec sh -c 'echo mv -v --backup=t "$0" "${0//['\\\''\"\`]/___}"' {} \;
    $ find -mindepth 1 -exec sh -c 'echo mv -v --backup=t "$0" "${0//[$(echo -e \\x27)\"\`]/___}"' {} \;
    mv -v --backup=t ./a b ./a b
    mv -v --backup=t ./' ./___
    mv -v --backup=t ./___ ./___
    mv -v --backup=t ./'"' ./_________
    mv -v --backup=t ./$0 ./$0
    mv -v --backup=t ./___.~1~ ./___.~1~
    mv -v --backup=t ./a ./a
    mv -v --backup=t ./$(echo crash) ./$(echo crash)
    mv -v --backup=t ./_________ ./_________
    mv -v --backup=t ./" ./___
    mv -v --backup=t ./''' ./_________
    mv -v --backup=t ./_________.~1~ ./_________.~1~

  • How to user PowerShell -replace to remove the dreaded em dash from a file name?

    I have a bunch of .msg files in a directory and want to zip them up (to send them to our spam filtering company), but I keep getting errors on file names that contain the em dash (—).  I believe it's (char)0x2014.
    [edited]... the correct syntax is [char]0x2014.
    I wish to eliminate the em dash in the file name but I can't seem to find anything on the web about replacing em dashes.  When I paste '—', PowerShell replaces it with a '-'.
    I found this neat function that does a great job replacing multiple characters within a string.
    http://powershell.com/cs/blogs/tobias/archive/2011/04/28/multiple-text-replacement-challenge.aspx
    I am using the below code for my string replacement.
    Thank you for your help.
    function Replace-Text {
    param(
    [Parameter(Mandatory=$true)]
    $text,
    $replacementlist = "(-,,',,%,,$,,@,,#,,&,,’,"
    Invoke-Expression ('$text' + -join $(
    foreach($e in $replacementlist.Split(',')) {
    '.Replace("{0}","{1}")' -f $e, $(
    [void]$foreach.MoveNext()
    $foreach.Current)
    $path = '<path>'
    Get-ChildItem -Path $path | Rename-Item -NewName {(Replace-Text $_.Name).trim()}

    Here is a simple filter that will strip out all nonprintable chanracters.
    $newname=$file.Name -replace '[^a-zA-Z\.]'
    I just tested it on Win 7 which supports has a Unicode filesystem and it successfullstrips the bad characters.
    We also need to do this on files uploaded to SharePoint and OneDrive.
    The ~ and other similar characters are not allowed in may systems.  You should keep a translation log and tag all renamed files with some obvious tag.
    ¯\_(ツ)_/¯

  • I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with   - how can I change this?

    I am using OSX 10.9.5 and Outlook Web App for emails. When I download an attachment it replaces the space in the file name with %20  - how can I change this?

    Click on the below link :
    https://get.adobe.com/flashplayer/otherversions/
    Step 1: select Mac OS  X 10.6-`0.`0
    Step 2 : Safari and FIrefox
    Then click on " Download Now"  button.

  • Suggest file name in JFileChooser?

    I'm a newbie (student) to both Swing and Java in general. In using JFileChooser, It occurred to me that it would be nice to offer a suggested file name when saving files.
    For those of you who have used MS Word, when one saves a new file, Word offers the document title or a few words of the document's first line as a suggested file name. This suggestion is displayed in the file name textbox of the save file dialog.
    Is it possible to do this sort of thing in Java and with JFileChooser? If so, how?
    Thanks in advance for any feedback.

    JFileChooser  fc = new JFileChooser(".");
    fc.setSelectedFile(new File("AnyFileNameYouWant.txt"));

  • Easy -- default file name in JFileChooser

    Hello,
    I have a JFileChooser dialog ready and working. I select the directory, then input the file name and press Save.
    The enhancement I would like to add to the dialog would be displaying a default name already in the FileName field once the dialog is opened. For instance "REPORT_ONE_" and then I would only add some text to the end of the default name. This would save me from typing the "REPORT_ONE_" all the time as this would already be displayed in the filename field.
    I could add the "REPORT_ONE_" to the filename later, when saving the report. However appending anything to the filename "behind the scenes" is not acceptable by the customer. They need to see the filename, not guess it.
    Looking forward to your help, fellow forum users.
    Thank you!
    aulo

    Thank you, 5p given.
    However this is what I execute and in my file chooser dialog the filename field is still blank.
      ExampleFileFilter filter = new ExampleFileFilter();
        filter.addExtension("html");
        filter.addExtension("csv");
      JFileChooser chooser = new JFileChooser(new File("REPORT_ONE_"));
        chooser.setDialogTitle( "Save Report" );
        chooser.setFileSelectionMode(chooser.FILES_AND_DIRECTORIES);
        chooser.setFileFilter(filter);
        int returnVal = chooser.showSaveDialog(this);
        ...It is in try-catch, no errors are returned.
    Operating System: WindowsXP
    Java Version: 1.3.1

  • Find and replace characters in file names

    I need to transfer much of my user folder (home) to a non-mac computer. My problem is that I have become too used to the generous file name allowances on the Mac. Many of my files have characters such as "*" "!" "?" and "|". I know these are problems because they are often wild cards (except the pipe). Is there a way that I can do a find and replace for these characters?
    For example, search for all files with an "*" and replace the "*" in the file name with an "@" or a letter? I don't mind having to use the terminal for this (I suspect it will be easier).
    Is this possible? Does anyone have any suggestions?
    Thank you in advance for any help you may be able to provide.
      Mac OS X (10.4.8)  

    Yep.
    "A Better Finder Rename" is great for batch file renaming.
    http://www.versiontracker.com/dyn/moreinfo/macosx/11366
    Renamer4mac may be all you need.
    Best check out VersionTracker. In fact everybody should have this site bookmarked and visited daily.
    http://www.versiontracker.com/macosx/

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

  • Replace not latin characters from file name.

    Dear friends,
    I tried a lot but even after reading the documentation about all the available CF functions I could not find a way  to accomplish this:
    As you already know from my previous post I'm trying to finish an application which manages multiple images. I have reached a really good point and I was ready to implement the solutions you suggest on this post when the client did something marvellous. He uploaded some images named "Εικόνα 123.jpg" (Image 123.jpg in English) which actually broke the Flex application that retrieves the images because the firewall does not allow high bit characters to go through. I now need to add a function that will evaluate every character in the file name individually and it will remove or replace (I do not care) all the characters that are not latin or numbers (spaces, greek characters, special characters, etc). As I've already said no known function is able to do that (as far as I know of course) and I guess that the solution could be hiding in regular expressions which is not my strong point. So I need your help here.
    Thank you in advance,
    John

    Thanks Ian,
    I cannot figure out how to use asc() function for this. I will have to run a test in every single character and replace the invalid ones but I will never now the actual string length (how many characters each image name will have) and I will  possibly end up destroying the extensions (.jpg) as well. To make it a little more complicated let me tell you that I will have to run this twice. Once for the full image path (ie d:\company\aptown\images\Εικόνα 123.jpg) in which I will have to change only the ...Εικόνα 123... part and not anything else, and once for a comma separated list of the image names (ie Εικόνα 123.jpg, Εικόνα 124.jpg, Εικόνα 125.jpg, Εικόνα 126.jpg). And don't be misleaded from the pattern. The customer may upload an image named with a complitely different way using invalid characters though, for example "Αντίγραφο της Εικόνας 123.jpg" (Copy of the image 123.jpg in English).
    Seems to be impossible ,
    I hope it is not.
    Yannis

  • My file names have disappeared in grid view. Thery have been replaced with a dark bar along the bottom of the previews. If I toggle using the command u it hide the bar but I still can't see the file name. In list view all the file names are OK.

    My file names have disappeared in grid view. Thery have been replaced with a dark bar along the bottom of the previews. If I toggle using the command u it hide the bar but I still can't see the file name. In list view all the file names are OK.

    The dark bar is caused by the option "Show metadata below image".
    Check the settings for the metadata overlays in Grid view (basic and expanded) by clicking the little "badge" icon below the Browser and selecting "Edit". Is the filename still enabled in the list? And in a high enough position to have precedence for other metadata tags, if the space does not suffice to show all selected tags?
    Regards
    Léonie

  • Underscore randomly replaces forward slash in topic file names and topic titles

    The problem I'm seeing is similar to the discussion at http://forums.adobe.com/message/2564701 which dealt with random insertion of underscores in topic titles. That problem seemed restricted to underscores replacing spaces in Topic File names and was solved (for some people at least) by deselecting the setting   "Tools > Options > General > Use underscores in filenames." Playing with that setting has not worked for me when it comes to unwanted replacement of forward slashes.
    I'm running RoboHelp 9 and linking from FrameMaker 10. The unwanted underscores are seen in (1) the RH project and (2) the help output:
    (1) In RH project in some topic titles like this:
    I want to keep the forward slash. The upper topic title is wrong and the bottom one is correct.
    (2) In AIR Help output: search results and in the tab that appears above the breadcrumbs in the main right pane.
    I cant change the titles prior to generating output because, as Matt Sullivan wrote in the similar discussion, "...for topics created from linked FrameMaker 9 files, the Topic Title is not editable from the Topic Properties. If it was, at least I could change the offending titles prior to final generation of output. (though the titles would revert on the next update of the FrameMaker source content)."
    I've double-checked the source FrameMaker documents and I can find no difference between Headings in which the forward slash is retained (desired) and those in which the forward slash is replaced by an underscore (unwanted).  Has anyone else seen this?
    Thanks,
    Matt

    Isn't the issue here that RH is creating filenames AND topic titles based on the FM title. Because of the slash it is saying that is an illegal character it changes the filename and the title in RH is based on that, hence both change.
    I don't know if that can be changed but now you can test to see if that is what is happening.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Batch Loader File Name - Replace/Append?

    We employ a custom/smart merge in FDM that automatically removes previously loaded intersections in HFM 11.1.2.1 by appending NODATA lines at the end of our load file based on the information included in the previous load file.  In the FDM configurations, users are only able to use the MERGE option when loading data so that this functionality is not subject to override.
    We have just purchased and developed a Batch Loader solution that we'd like to pair with this smart merge functionality and I want to be sure that we are requiring appropriate file name configuration based on a MERGE data load setting.  If I understand the file name conventions for batch loader correctly, the "RA", "RR", "AR", "AA" suffix at the end of the loader determines whether batch loader runs through a replace or append.
    If we want a location's file to replace the previous load file within FDM during the import step, but load all data files to HFM using a merge, should my filename end with "RA"?  Also, if someone accidentally uses RR, does changing the Adapter Option (FM11X-G5-ELoadOptMethodVal) to only show Merge protect against a replace load?
    Thanks in advance!
    S

    The Load Tags are as follows:
    Load Method for FDM: R,A
    Load method for Target System: R,A
    That is correct, if you want to do a replace in FDM and a Merge in HFM you would use RA or RM.
    RR would perform a replace in FDM and a Replace in HFM.
    You would need to test removing the Replace from the option in the adapter and see if it would fail for load.    

Maybe you are looking for