Why does JFileChooser.setSelectedFile behave this way?

Hello,
I'm trying to ovverride the setSelectedFile() method. However in doing so I've discovered the following:
Every user selection (single-click on a file/folder) results in two calls: one with the file null, and another with the selected file.
Why??
I could work around it, but i don't understand what sense it makes. I looked into JFileChooser code, and there doesn't seem to be an apparent 2nd call to setSelectedFile.
This is my work around code. However having to say if (f != null) { and   if (!f.getName().equals("Dir")) { doesn't sound enough data hiding for me.
class InstallDirChooser extends JFileChooser {
    @Override
    public void setSelectedFile(final File f) {
        if (f != null) {
            if (!f.getName().equals("Dir")) {
                super.setSelectedFile(new File(f, "Dir"));
            } else {
                super.setSelectedFile(f);
            System.out.println(getSelectedFile().getAbsolutePath());
public class NewClass {
    public static void main(String[] args) {
        final InstallDirChooser c = new InstallDirChooser();
        c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        c.setSelectedFile(new File("Dir"));
        int rVal = c.showSaveDialog(null);
        if (rVal == JFileChooser.APPROVE_OPTION) {
            final File db = c.getSelectedFile();
            db.mkdir();
}

I'm not sure what you're trying to do here, but at
first glance "TestK t = new TestK();" inside the for
loop seemed unusual.
If you place it before the loop it works fine.I guess what he is trying to ask is that why is that if you use the new operator in the code, you donot get the exception while if you dont use it you do get one. While in any case either you use it or not you are supposed to get a new String as per the String API.
Well thats an interesting observation and I have no explanation as to why is this happening. I do remember that thread where somebody pointed this out as a use of the String(String original) construtor. Furtehr adding on to that the API states about this constructor the following
Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.
so I donot get why not using it would cause the exception to be thrown. I have tested the code though and it seems to behave as pointed in the original post.
Interesting question though, food for thought.

Similar Messages

  • Why does the video freeze half way through my movie and the audio keep going?

    Why does my movie freeze half way through and the audio continues?

    Most likely this is due to running out of virtual memory. You can reset virtual memory by restarting your Mac.
    Long term you may want to consider purchasing more memory.

  • Why does the Safari message "This is a non-secure form" pop up everytime I try to use yahoo mail?

    Why does the Safari message "This is a non-secure form" pop everytime I go into yahoo mail?  If I don't press the send option my whole computer freezes.

    From the Safari menu bar click Safari > Preferences then select the Extensions tab. Turn that OFF, quit and relaunch Safari to test.
    If that helped, turn one extension on then quit and relaunch Safari to test until you find the incompatible extension then click uninstall.

  • Why does Safari ask me this every time I open my Macbook?  "NONE OF YOUR PREFERRED NETWORKS ARE AVAILABLE.  CHOOSE THE WI-FE NETWORK YOU WANT TO JOIN FROM THE LIST BELOW. "

    Why does Safari ask me this every time I open my Macbook?  "NONE OF YOUR PREFERRED NETWORKS ARE AVAILABLE.  CHOOSE THE WI-FI NETWORK YOU WANT TO JOIN FROM THE LIST BELOW. "

    Open System Preferences > Netwwork then click Advanced then select the Wi-Fi tab.
    Under Preferred Networks, if you see more than one network name listed, click and drag yours to the top then click OK.
    Quit and relaunch Safari.

  • I need help why does i send to this friend there is a redbox + x

    i need help why does i send to this friend there is a redbox + x , but i send to other friend there is no problem. for anorid samung s3 phone

    Are you sure you have the right pin for your other friend? Try deleting the contact and re-adding them. Also, BBM has to be approved in the countries of both parties.
    1. Please thank those who help you by clicking the "Like" button at the bottom of the post that helped you.
    2. If your issue has been solved, please resolve it by marking the post "Solution?" which solved it for you!

  • HT4901 Why does OS X have this poison pill?  What if iCloud isn't working one day; isn't it a security feature to keep a copy on the local machine?

    Why does OS X have this poison pill?  What if iCloud isn't working one day; isn't it a security feature to keep a copy on the local machine?

    Thank you Julian and Csound1.  Please help me understand these two messages that I get when I try to sign out from iCloud:

  • Why does "Link Media" behave differently when used as a keyboard shortcut vs when right clicked???

    Not sure whether anyone else is encountering this, but the "Link Media" command behaves differently when right clicked as opposed to when used as a keyboard shortcut.
    When you right click to select that option for an offline file, you get only the corresponding disconnected source media. But when you execute "Link Media" via a keyboard shortcut, PP brings up a huge list of all other offline media. Why does it only do that when you use the keyboard shortcut for "Link Media" but not when you right click "Link Media".
    I'd like to get the Link Media command to behave via the keyboard shortcut the same way it behaves when right clicked. I don't want to have to deal with relinking a hundred other files, but just the single offline file I'm working on.

    Among the alternatives not mentioned... Using a TiVo DVR, rather than the X1; a Roamio Plus or Pro would solve both the concern over the quality of the DVR, as well as providing the MoCA bridge capability the poster so desperately wanted the X1 DVR to provide. (Although the TiVo's support only MoCA 1.1.) Just get a third-party MoCA adapter for the distant location. Why the hang-up on having a device provided by Comcast? This seems especially ironic given the opinions expressed regarding payments over time to Comcast. If a MoCA 2.0 bridge was the requirement, they don't exist outside providers. So couldn't the poster have simply requested a replacement XB3 from the local office and configured it down to only providing MoCA bridging -- and perhaps as a wireless access point? Comcast would bill him the monthly rate for the extra device, but such is the state of MoCA 2.0. Much of the OP sounds like frustration over devices providing capabilities the poster *thinks* they should have.

  • Is it possible to prevent the history from moving entries up to the top of the list when a site is revisited, and why does it only do this sometimes?

    * Sometimes the history appears to compile previous visits to a site into only the entry for the most recent visit, but other times it does not. In other words, sometimes when a site is re-visited, the history will move a previous visit to that site out of the existing chronological sequence and put it at the top. What makes the difference in whether it does this or not, and is there any way to prevent the consolidating of information this way? I am using using Firefox v.27, Windows 7.
    I would like things to be in true chronological order for the possibility of accurately tracking previous activity, and for that purpose do not mind having the duplicate entries. Possible successful solutions might be in areas 1-3 below, and I would appreciate any suggestions.
    1. Are there any preferences in 'about:config' that apply to this? I could not find any.
    2. Are there other ways of getting this type of record, e.g. some other computer log, program, or add-on?
    3. What are some of the most accurate records of one's own internet browsing activity that one can make or obtain, with or without the browser's history function, if anyone knows?
    Thanks.

    Firefox normally only shows the most recent visit to a specific URL, so you would have to do extra effort to make older visits visible (place:sort=4&type=1).
    *https://developer.mozilla.org/en/Places_query_URIs
    See also:
    *http://www.nirsoft.net/utils/mozilla_history_view.html

  • Why does 3Dmark05 give me this error?

    This is a version I got off Limewire and its not full retail. Its only a demo. Got this error:
    IDirect #DDevice9:Present failed:Device lost(D3DERR_Divice Lost)
    I have the latest drivers off the Nvidia website. What gives? Never used 3d05 before, but I was just testing my new ASUS hybrid card with various benchmarks to make sure things seem to be running right. I do get a posted score in 3dmark05, even though it kicks me out and zaps my screen temporarily to 800X600. 3dmark05, after clicking the ok buttun after the error message posts my score 3,106 which seems about right seeing that I have a slower system.
    So far I have only benched this card, havent played any games for more then ten minutes. graphics seem better.Im not seeing the improvements in Far Cry that I though I would get from a 6800GT on full settings. I know this is a DDR128, but I just though things would be a smoother. Clarity is much better then the 9800pro and this card runs suppringly cool that 6600GT I tested was dangerously hot and I didnt want anything that hot in my case.
    I dont think there is anything wrong with the card. I tested a 6600GT the other week and the this 6800GT hybrid did get me from 43K to 46K on Aquamark3. My 9800pro was at 41K with a slight overclock.....maybe I try some Farcrytests to see if that shows anything...
    BTW I just was going to tell you have the latest drivers and was going to post the version, because after I got the card up and running I downloaded the latest from Nvidia.  Why does my Display Adapter when I click on properties say "7/9/2004" version "6.2.1.1"?....Now when I ran the driver update, it said it was updating the drivers and the drivers name they were version 9/13/05?

    Quote
    >It sounds like the version you got may be damaged. I would try getting the download directly from futuremark. The link >to download it is http://www.futuremark.com/download/?3dmark05.shtmlQuote
    I tried it with another version of 3Dmark05 and got the same error. I also noticed it does it during the CPU test where it tries to make the CPU think its a GPU. I found this:
    http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/graphics/programmingguide/gettingstarted/devices/lostdevices.asp
    I also checked around the net. Seems like there are two reasons for this "lost" error. A resident program pissing 3dmark05 or a voltage issue....I havent had any problems with my system and only have then with 3dmark05. This is with a new version of 3dmark05 and newest drivers installed after Driver Cleaner. SO I still dont know whats up....Again it only does it durring the CPU test for 3Dmark05 and in particular always errors out right when the monster is emerging from the water During the zepplin test.
    Quote
    >As far as the jump is scores, that does not seem like enough going from the 9800 to the 6800. I was able to play >FarCry on my machine will ultra settings with my 9800 (but no anti-aliasing or ansiotropic filtering). And only going from >41k to 46k with aquamark also seems low. Did you use a drivercleaner to fully remove your ATI drivers? If not I would >remove both the NVidia drivers and get the cleaner and clean both ATI and NVidia drivers off of the system and >reinstall your NVidia drivers.Quote
    In my previous post I noted that I was only using the ASUS drivers dated 4/05. Well I went back and used Driver Cleaner then tested. The scores were about the same, but gameplay and visuals were much smoother as I would expect from a card like this. I though that was odd given I had  pretty much the same scores(meaning Aquamark stayed the same and 3dmark went up about 300 points). I then went back to Nvidias site and got the newest drivers and they loaded right this time
    Aquamark: increased 1,000 overal to a solid 47,000-47,500  (I was getting 41K with 9800pro,XTbios OC)
    3dmark03: 9608 (from 9137)
    3dmark05: same score no changes (as noted above still errors out at CPU test)
    Thanks for the input I am VERY happy to be running solid 47000-47500 Aquamarks where as before I was runnign 45500-46000 with driver issues. I not as familiar with 3dmark scores and how the differences pan out when playing games. But you mentioned that My scored seemed low. Is this 47,500 more like what you thought? Also remember the card that I have is a 16,6 6800 GT but has 1ddr128. In this review this guy only gets for 3Dmark03 10,290(vs my 9,608) but he has a 64 bit system. In another review using 3Dmark05 the guy gets 3,838 vs my 4,060 Here the card with some scores:
    http://www.digit-life.com/articles2/gffx/nv40-11.html
    http://www.ap0calypse.com/showthread.php?t=1287
    Things of note:
    1.) Graphics seemed less chopy by just using driver cleaner, but scored stayed about the same.
    2.) After gettting the latest drivers too. Aquamark showed a significant change, yet 3d05 stay the same
    3.) Question Driver Cleaner said to "empty the recycle bin" while in safe mode. I couldnt do this. How do I do that?
    4.) All this with the 1.3 Far Cry patch makes the game much nicer. I can do Full Blast settings, but there is some screen rippple every 15 seconds or so. Not to bad, But not flawlwss like a 64 bit system.

  • When I open a new link and then switch back to the original page why does it go all the way back to the top of page?

    Scroll to the middle or bottom of a page with many links (like ebay) then close the link and when it returns to original page you are sent all the way back to the top of the page, why does it not switch back to the area of the page I was originally viewing?

    Try here:
    Tools > Options > Applications
    Enter JPEG into the search box and change any that say "Save file" to "Always ask".
    Does it work?
    Edit: Forgot one other relevant setting. On:
    Tools > Options >General tab
    pick "Always ask me where to save files"
    All good now?

  • HT5439 Why does support *** u me this statement gets the problem solved ? Use Apple Configurator* to deploy a configuration profile with a Wi-Fi payload that contains the proxy configuration.

    Why does apple support help *** u me this opening statement help anyone without the knowledge to undertand what to do?
    Use Apple Configurator* to deploy a configuration profile with a Wi-Fi payload that contains the proxy configuration.

    Post in your native language, nothing posted so far makes any logical sense.

  • Why does photo booth do this?

    Whenever I make a video or start one it keeps closing and showing this message about That is closed unexepectly and I should report, ignore, reopen. Why does this keep happening/

    Marie
    You can enhace your knowledge by checking out the many video and PDF tutorials at the Adobe Support centre here:
    http://www.adobe.com/support/photoshop/
    You can also access that page from Photoshop via the F1 key.

  • Why Does FireFox Crash on this page?

    After resetting Firefox, it still crashes on this html page, even though Chrome and IE have no problem with it.
    http://howtothinksideways.com/zdevDanAllen/firefoxnotcrash.html
    Why?
    This page does not crash...
    firefoxnotcrash.htm
    The difference between the two pages is right at the end, were the crashing file has a valid < to open a <div tag, where the non crasher has the < removed. Evidently, FF does not like that div.
    An error message instead of crashing and taking all the system memory would be something the developers might want to consider adding in a future release. I would vote for adding the error message and removing the password deleter that can unannouned with the last upgrade.
    man....
    p.s. I would have to say, Firefox's way of crashing when no other browsers crash, with no error message and taking all the system memory from my computer into its death dive, has to be worst but I ever saw.

    I did every step, same result. My gf is not getting the problem on her computer, I am trhing a reset;. sheez.
    Still does not answer my question. I did not ask how to fix it. I asked why this is happening?

  • Why does the Video do this?  Why is iMovie doing this all of a sudden

    http://www.esnips.com/doc/407a5579-501f-44a4-ad41-789684ea36ca/GIf-Remastered-Co medy-2
    WAtch it. near the beginning, the video just freezes and my vid has a lot more.
    Why is it doing this in imovie and how can I fix this?
    I used mov and mp4 and they bot h did this. I made 2 other videos last night and it didn't od this. This one did.
    I tried all thes tuff but it freezes in the video. I don't know why but it happens. how can I fix thi?

    Hi M
    That the Video freeses can have many origins. Most common is:
    - less than 5Gb free space on internal hard disk
    - use of external hard disk that is formatted FAT32 /DOS/UNIX/Mac OS Exchange
    should be: Mac OS Extended or Mac OS Extended (journaled)
    - other background processes running: Screen/Energy savers, photo as desktop
    backgroud - even worse if it changes every 5th second
    If You got > 25Gb free, no ext. hard disk and a clean desktop:
    Deleting iMovie pref file - should help
    iMovie
    -->/Users/YourName**/Library/Preferences/com.apple.iMovie.plist
    and
    -->/Users/YourName**/Library/Preferences/com.apple.iMovie3.plist
    AND I would also
    - Run: Repair permisions: Apple Disk Util tool (on hard disk/Applications/Tools/Disk Util tool
    and I would also
    - Run: Repair hard disk: Apple Disk Util tool - to do this You need to start from
    CD/DVD or external hard disk !
    Yours Bengt W

  • Why does InDesign / CS3 do this?

    When exporting an InDesign file to pdf, we frequently end up with the pdf having a different name than the original ID file.
    We thought that maybe the ID file is retaining an old pdf name because we may have opened an old file, done a save as and made a new file.
    Is this the case, and if so, why is it happening?
    And ... how do we make the pdf retain the name of the InDesign file without making an .inx file and ending up with duplicates or retyping the file name every time?
    Thanks for any help/suggestions!

    > It's frustrating because we ... have to actually pay attention (!) to whether the pdf is taking on the correct name.
    Golly Gee! It is so frustrating when graphics software makes you pay attention to what you are doing.
    Actually, InDesign does not stick with the last name of the file. It sticks with the
    b name of the last exported pdf.
    This is the benefit that Buko takes advantage of.
    However, if you understand how InDesign retains the name of an exported pdf, you can avoid the problem of the "wrong" name in the pdf file.
    The name of an exported pdf does come from the name of the file.
    If you work on a file, and then save your work, and
    b then make the pdf,
    you will notice that InDesign is asking you to save your work again when you go to close the file.
    The "changes" that InDesign is asking you to save is the name of the pdf and its settings.
    Now, if you don't save the changes to the file after you export, InDesign will retain the default state of the name for the pdf. That default state is the ability to pick up the name of the file.
    This means that you could do the following:
    Work on file xxx.indd. Save your work.
    Export file. The default xxx.pdf will appear.
    Close file xxx.indd.
    b Don't save your work.
    Open file xxx.indd.
    Save as yyy.indd.
    Work on file yyy.indd. Save your work.
    Export file. The default yyy.pdf will appear.
    Close file yyy.indd.
    b Don't save your work.
    Open file yyy.indd.
    Save as zzz.indd. (and so on)
    The bottom line is that the export as pdf will pickup the name of the file as long as
    b no saves were done after an export with any name.

Maybe you are looking for

  • Error KI235 - Account requires an assignment to a CO object

    Hi gurus, I just wanted to ask re: thjs issue of ours wherein we can't release a billing document to accounting (VFX3) and system issues error message - KI235 (account assignment missing). In OKB9, the profit center assignments have already been set.

  • OAS10g to Weblogic 11gR1

    We have a JSF application completely developed in JDeveloper 10.1.3 with ADF and Toplink, which is developed on OAS 10gR3 in oc4j. We will soon start working on migrating this to Oracle WebLogic Server 11g R1. With the OAS and Weblogic merge I am a l

  • Regarding ZVAT

    Dear all, 1 In case of Traders Basic Value + Vat        =   Purchase value E.duty +Vat                 =   Tax [Vat] 2 In case of Manufacturers Basic valueE.dutyVat   = Purchase Value E.duty +Vat                 =   Tax [Vat] The above mentioned repo

  • How to stick the ends of line shapes together?

    Hi, as shown in the picture I mannualy moved three lines to form the shape like this. Anybody knows is there a way to stick these three line together? THX

  • Can be done restore from an earlier backup if the backup was deleted?

    can be done restore from an earlier backup if the backup was deleted? restoring from backup is lost application