JFileChooser - filename going away on switching directory

When the JFileChooser opens up, a selected file name can be shown in the file name edit box. However, as soon as the user switches directories, it is cleared. Is there any way to make the filename stay after switching directories?
A perfect example would be in a "Save" dialog box. The default file name for the file to save is shown, but as soon as the user switches directories, the file name is cleared.
Is there a way to listen for a directory change within the JFileChooser (ie a fire event method? or action listener?) and re-set the filename? Is this a flaw in JFileChooser design? Am I just missing something obvious?
I've seen this in multiple Java applications and it is very inconvenient for the user.

This is the only way I could think of doing it. However, if you manually change the filename, then click on a new directory, it will change the filename back to the default one. This is the best option I could think of right now.
    final String defaultFileName = "test.txt";
    final JFileChooser dlg = new JFileChooser(".");
    dlg.setSelectedFile(new File(defaultFileName));
    dlg.setFileSelectionMode(JFileChooser.FILES_ONLY); // doesn't work...the following is a work-around
    dlg.addPropertyChangeListener(new PropertyChangeListener()
        public void propertyChange(PropertyChangeEvent pce)
          if(pce.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY))
            dlg.setSelectedFile(new File(pce.getNewValue() + File.separator + defaultFileName));
  int result = dlg.showSaveDialog(...);
  if(result == JFileChooser.APPROVE_OPTION)
    // create and save the file in dlg.getSelectedFile()
  }

Similar Messages

  • My i phone 4 wont switch on the apple sign just keeps coming up the going away any help

    my i phone 4 wont switch on the apple sign just keeps coming up the going away any help

    My phone is doing the same away and I tried what you said, jpm12, but the apple sign still keeps coming up and going away.

  • JFileChooser: filename changes when i change directories

    Hi,
    I'm having a problem with a file chooser : when changing directories (change from default directory to dir of my choice), the "Filename:" text gets changed too.
    Here is what is actually happening :
    - I use setSelectedFile(<default file>) on my file chooser before opening
    - it opens with <default file> in the Filename field.
    - I switch to a different directory by double clicking within the area which shows the directories and files.
    -->> problem : my filename takes the name of the directory which i double clicked.
    ** surprisingly enough , when i select a directory from the drop down list of the filechooser the above problem doesnt happen .
    Below is my code. cud someone tell what is missing/wrong. plz treat this as urgent , i got to ship the code after 4 hrs
    Thanks in advance for any help, i will more than glad to offer duke dollars for this one.
    KG
    public class StepSaveFileDialog extends JFileChooser  {
        String fileExtension = null;
        JFileChooser fileDialog = null;
        String reportName = null;
          public StepSaveFileDialog(String fileExtension,String reportName) {//used to get the fileextension and the reportName
            this.fileExtension = fileExtension;
            this.reportName = reportName.replaceAll(" ","_"); 
          public String getSaveDialog() throws IOException {
            String filePath = null;
            fileDialog = new JFileChooser();
            fileDialog.setDialogType(JFileChooser.SAVE_DIALOG);
            fileDialog.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            fileDialog.setAcceptAllFileFilterUsed(true);
            fileDialog.setFileFilter(new StepFileFilter(this.fileExtension));
            String dfltFilePath = ReportEngine.getDefaultReportSavePath();
            File selFile = null;
            String date = new StepDate(System.currentTimeMillis()).toString();
            date = date.replaceAll("/","");
            reportName = reportName + "_" + date;
            if (dfltFilePath != null) {
                selFile = new File((new File(dfltFilePath)).getCanonicalPath() + "\\" + reportName);
            }else{
                selFile = new File(reportName);
            fileDialog.setCurrentDirectory(selFile);
            fileDialog.setSelectedFile(selFile);
            int option = fileDialog.showSaveDialog(StepMainFrame.getInstance());
            if (option == JFileChooser.APPROVE_OPTION) {
                selFile = fileDialog.getSelectedFile();
                    File reportFile = new File(selFile.toString());
                    boolean success = reportFile.createNewFile();
                    if (!success) {
                        fileDialog.show();
                        fileDialog.setVisible(true);
                        int overwriteOption = JOptionPane.showConfirmDialog(
                                fileDialog, selFile.getAbsolutePath()
                                        + StepStatusMessage.PROMPT_FOR_OVERWRITE);
                        if (overwriteOption == JOptionPane.NO_OPTION) {
                            filePath = getSaveDialog();
                            return filePath;
                    filePath = reportFile.getAbsolutePath();
            return filePath;
    the ReportEngine.getDefaultReportSavePath() is like this
    private String getDefaultReportSavePath() {
            Properties prop = new Properties();
            String dfltFilePath = null;
            try {
                File file = new File(CONFIG_FILE);
                FileInputStream inputStream = new FileInputStream(file);
                prop.load(inputStream);
                inputStream.close();
                dfltFilePath = (String) prop.get("step.reportFilePath");
            } catch (IOException ioe) {
                StepStatusBar.getInstance().writeErrorMessage(ioe.getMessage());
                StepLogger.getLogger().fatal(ioe.getMessage(), ioe);
            return dfltFilePath;
    }the fileFilter is like this :
    public class StepFileFilter extends javax.swing.filechooser.FileFilter {
        String fileExtension = null;
        public StepFileFilter(String fileExtension) {
            this.fileExtension = fileExtension;
        public boolean accept(File f) {
                return f.isDirectory() || f.getName().toLowerCase().endsWith(this.fileExtension);
        public String getDescription() {
            return this.fileExtension;
    }

    You will still be able to navigate through the area
    where the files and directories are displayed with
    FILES_ONLY. Clicking on a file will cause its name to
    appear in the File Name field, while double-clicking
    on a directory will navigate into it.
    FILES_AND_DIRECTORIES causes the names of both files
    and directories to appear in the File Name field when
    they are clicked.
    MikeHey Mike , thanks a lot .... it worked

  • Is WebDynpro for Java going away?

    Hi,
    Is SAP planning to completely Switch from Webdynpro for java to webdynpro ABAP? What is the future for Webdynpro for java in that case? Like old ITS technology will SAP completely remove support for WebDynpro for Java development!
    With Regards,
    Nitesh Shelar

    Please refer ht[WD for Java going away??|WD for Java going away??]

  • With Mobile.me going away soon, where will I be able to upload my iWeb pages. iCloud?

    Where will iWeb upload to after Mobile.Me goes away?  As a high school English teacher, I have developed thousand(s) of highly interactive pages of tutorials, tests, keys, lesson plans, etc., that my advanced and learning challenged students have come to rely on.  The last thing I want to do is develop these pages even more without first knowing what will become of my work:  thousands of hours of work.  Uploading to a non-Apple FTP is an option, but then the webpages lose password protection, blogging capabilities etc.  I need an Apple solution...which is what I have always relied on for over 25 years. Using Google.docs would be like retuning to the Stone Age.  Any viable solutions?  I have talked with the Apple Help center folks, but they have no answers to date.  Thanks.

    I don't think so.  Steve replied to an email saying that we would have to look elsewhere for hosting our sites. 
    You can use a 3rd party server and retain password protection on a site or page by page basis. 
    For what it's worth I signed up with HostExcellence several days ago with their Ultimate Business plan at $8/mo.  That's a wee bit less than MMe was but with that I get 3 free domain names , unlimited space and bandwidth, email addresses, subdomains and 24/7 ear-to-ear excellent customer support.
    Within a few hours I had my Demo and tutorial sites moved and up and running.  Pretty simple actually. I used Transmit to open my new server and my iDisk so I could drag and drop from the iDisk onto the HE server. Just like copying from one of my hard drives to another. 
    Each of the domain names can have an email address and several alias.  
    As far as a hit counter you'll need a 3rd party one.  I use StatCounter and that gives me so much more than just visitor counts. It gives me their location,  what site the visitor came from, what browser used, what system the visitor was running and lots more.  I've written a tutorial on how to install it: #13 - Adding a StatCounter as an HTML Snippet.
    For many of my sites I've put them in my primary domain name account, oldtoad.net.  So the URL to my Demo_1 site would be oldtoad.net/Demo_1.  Same for my Toads Cellar website folder. Copied it into the oldtoad.net directory and the URL for the cellar became oldtoad.net/ToadsCellar, short and sweet. 
    I had been contemplating this move for quite a while now and the latest round of events and help from longtime HE user and friend, Roddy McKay, got me off my duff and started. Now I wish I had made the move earlier.
    Publishing to HE is no different that to MMe.  You can either publish directly with iWeb or to a folder on your hard drive and then use a 3rd party FTP client from there.   Since I optimize my sites with Website Maestro I publish to a folder and let WSM optimize and upload to the server.
    Since we have a year before MMe is history one can take time to move to the new server and get things straightened away before going live with the new sites.
    OT

  • When typing in the Find Bar, sometimes the caret goes away without clicking or moving the mouse. This also happens when backspacing in the Find Bar, and results in going back one page in the browser. How can this be remedied?

    Sometimes the carat goes away after one letter, while other times I can get an a few letters in before having to re-click inside the text box in the bar.

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Mail is checked continuously. The "thinking circle" never goes away

    The little "thinking circle" right beside the 3g label in the top left hand corner never goes away in my mail app. This just started happening within the past week. This wouldn't be so bad if it wasn't chewing up my battery and bandwidth. Does anyone know why this might be happening or how I can make it stop?
    I have mail set to check every 15 minutes, but it just keeps checking continuously. I check yahoo and gmail accounts.

    My Ipad started doing the same thing this past week(5-6 times,and I am on manual), I tried switching app's and going back and it was still running. I then went to email sent, and after the sent mail was loaded I went back to mail, and it then loaded my new messages. suerte...

  • Firefox in Windows. When I click on a link, Firefox will hang up with a rotating cursor. Problem goes away by moving mouse. This does not happen with IE.

    Using Firefox 27.0, when I click on any link, a rotating cursor appears and continues to rotate. Moving the cursor will solve the problem. I have had this problem for several versions of Firefox, and I use auto updates.

    Hello,
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * On Windows you can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac you can open Firefox 4.0+ in Safe Mode by holding the '''option''' key while starting Firefox.
    * On Linux you can open Firefox 4.0+ in Safe Mode by quitting Firefox and then going to your Terminal and running: firefox -safe-mode (you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    [[Image:FirefoxSafeMode|width=520]]
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    ''When you figure out what's causing your issues, please let us know. It might help other users who have the same problem.''
    Thank you.

  • Help my iPod won't let me download apps... I'll put my password in then it takes me to the app but then is just goes away then I do it again an it won't load or it will just go away again plz help I want to get apps

    Help my iPod won't let me download apps... I'll put my password in then it takes me to the app but then is just goes away then I do it again an it won't load or it will just go away again plz help I want to get apps

    You said you updated yur 1G iPod to 4.2.1. A 1G can only go to 3.1.3 and thus you must have jailbroken it to get to 4.2.1 and that can cause problems.
    ArealDJ wrote:
    I have the same problem.. apps won't download and won't open. I have a 1st Gen ipod touch and recently upgraded my MacBook Pro (2012) and as soon as I upgraded the iPod Touch to 4.2.1, this happened. I restored to factory defaults and still cannot dl and open apps. Any way to diagnose this problem? Apple tech charges $29.99 for out of warranty products and if I am reluctant to pay with them telling me its simply a hardware problem.

  • Can some body give me an advice, my cursor can not be controlled after I shut it down, and open again. But this problem goes away after I closed and opened the lid

    Can some body give me an advice, my cursor can not be controlled (using pad) after I shut it down, and open again. But this problem goes away after I close and open the lid.

    Boot from your OS installer disk and run Repair Disk from Disk Utility.

  • The curser includes a text box from a previous image or link when the curser is positioned on the side of the page. i click and it goes away but only to return again on the next launched page. how do i get rid of this?

    the cursor includes a text box from a previous image or link when the cursor is positioned on the side of the page. it will mainly happen when i hit "back" from the page i was on. i click and it goes away but only to return again on the next launched page. i also keep several tabs open and it will carry over to any one of them i go to. how do i get rid of this?
    == This happened ==
    Every time Firefox opened
    == when i upgraded to most recent version 3.6.8

    A number of extensions can cause that problem, you'll need to do a little troubleshooting to find out which extension is causing that to happen for you.
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • I get "an error has occurred in the script on this page" it comes up for no reason on Firefox and I can't remove the message, it then goes away on it's own after 3 minutes? how do I prevent this message coming up? I have Windows 7.

    I get "an error has occurred in the script on this page" it comes up for no reason on Firefox and I can't remove the message, it then goes away on it's own after 3 minutes? how do I prevent this message coming up? I have Windows 7.
    I can work the screen behind the message which stays in the centre of my screen.

    Windows version is...?
    What pages are giving you problems? [post links to same]
    Are you getting the script errors only when attempting to print or...?
    Has your printer's manufacturer confirmed that your currently installed printer software is IE11-compatible (yet)?
    ~Robear Dyer (PA Bear) MS MVP-Windows Client since 2002 Disclaimer: MS MVPs neither represent nor work for Microsoft

  • HT201317 I have a MobileMe account and have shared many MobileMe Galleries.  MobileMe Galleries are going away in June.  How can I share a photo album with others using iCloud?

    I have a MobileMe account and have shared many MobileMe Galleries.  MobileMe Galleries are going away in June.  How can I share a photo album with others using iCloud?

    The new ios version of iPhoto allows sharing.  Here's a blurb from Apple's web site:
    There’s the old way of creating photo galleries, then there’s the iPhoto way. Select a group of photos and iPhoto automatically flows them into a beautiful journal that’s fun to personalize and share online. Touch a photo to make it bigger or smaller. Or drag it to a different spot on the screen. iPhoto adjusts the page around whatever you’re doing, so your journal always looks great. You can even add captions, maps, dates, and weather — giving family and friends the big picture at a glance.
    More things you can do:
    With iPhoto, there’s more than one way to share a photo. Post pictures directly to Facebook, Flickr, or Twitter. Play an impromptu slideshow on your iPad or iPhone. Or stream photos to your HDTV to give your big moments room to shine.
    I have not used ios version of iPhoto to share "journals" and I'm not sure this is part of iCloud or not.  You'll have to do a google search on "ios iphoto" and read up of this journal thing.  As far as I know, this is the only way of sharing photos.  I'm not sure whether other friends use a browser to view these journals or whether they need something special.  Any way - search around to find answers.

  • How can i reset my app store setting? i have signed in and out with my own apple id but i used a different one at first and that one is not going away

    How can i reset my app store setting?
    I have signed in and out with my own apple id but i used a different one at first a few years ago and that one is not going away how do i change it to my own apple id?

    Content and Apple IDs -
    Content is forever tied to the Apple ID that bought it. Apple does not transfer content from one Apple ID to another. Apple does not merge Apple IDs. You will never be able to access your content bought with one Apple ID with a new Apple ID. Your only option is to delete the content and buy it again with the new Apple ID.

  • I keep getting a pop up asking for my voicemail password.  I can simply press cancel and it goes away, but it happens frequently and often during a text or email.  Is there a way to stop this?  I don't even have a voicemail password.

    I keep getting a pop up message asking for a voicemail password.  I can simply touch cancel and it goes away.  Put it pops up quite frequently during texting, chatting or email.  Is there a way to stop this?  I don't even have a voicemail password.

    Contact your carrier; they are the only ones who can resolve this for you. Use the Carrier Luke,
    "Fun with the Sun, MEta"

Maybe you are looking for

  • Lsmw converted file path

    hi all, i am loading sales order using lsmw direct input, and find a question. is it a must to specify a logical path and file name for the converted data at step specify file? at first, i didn't specify it and at the last step, i choose the flat fil

  • Photoshop CC 2014 - Window Libraries Missing

    Watched the Adobe Keynote and looked at Help files about using this new feature. In my Photoshop CC 2014 under Window I should have a Libraries option. I don't. It just goes from Layers to Measurement Log, nothing in between. I checked for updates th

  • Pages '09: mailmerge from AddressBook AND a Number document ???

    I have a +Pages '09+ document in which I have successfully associated mailmerge placeholders with fields in, first, +Address Book+ ; and, second, a Numbers document. But when I try to run the Merge from Edit > Mail merge, either the fields from one (

  • Image with transparent background changes surrounding fill color when PMS...

    Hello. I have a .PSD image I'm using in InDesign CS3. It's a greyscale image with a transparent background. When I bring it into InDesign and set the background color of the image box to a Pantone and then print it, the PMS color within the area of t

  • My itunes stopped working after downloading the latest update.

    what do i need to do to get my itunes working again and how do i get my library back?