JFileChooser.showSaveDialog and Filename field

I am implementing the actionPerformed method for a "Save As" menu command. In my standard JFileChooser "Save" dialog (showSaveDialog, Metal L&F), I volunteer the current filename (by a previous call to setSelectedFile). The dialog opens just fine. If the user selects a file in the list, the name of the selected file appears in the "File name" textfield as expected. But if the user selects a directory in the list, the name of the directory likewise appears in the "File name" textfield.
From other programs (including JBuilder4) I am used to having the filename stay put when I select and/or open a directory in a Save Dialog. Is this just the way a JFileChooser save dialog works in the Metal L&F, am I doing something strange, or is there a workaround?
Thanks very much.
    File tempFile = new File( activePI.getPathname() );
    defaultSaveDir = tempFile.getParentFile();
    JFileChooser chooser = new JFileChooser(defaultSaveDir);
    chooser.setSelectedFile(tempFile);

Thanks to both of you for the help. I actually came up with the key element of trevorryan1's solution shortly after posting my followup yesterday: consuming any setSelectedFile call when the file argument is a directory. Once this test is in, the counter etc is no longer needed! I consider the JFileChooser's "overwrite the filename textfield" behavior to be a bug, since my !file.isDirectory() override of setSelectedFile shouldn't do anything that setFileSelectionMode(JFileChooser.FILES_ONLY) doesn't already do (FILES_ONLY is the default setting).
Here is the test class that I posted to the BugParade; I'll post the URL when/if it shows up.
import java.io.File;
import javax.swing.JFileChooser;
class JFileChooserBug
  //Note: comment out the first or second declaration of JFileChooser chooser
  public static void main(String[] args)
    // 1. in a standard JFileChooser save dialog, navigating to another
    // directory will (inappropriately) overwrite the "File name:" textfield.
    // This should not happen when fileSelectionMode = FILES_ONLY (the default).
    JFileChooser chooser = new JFileChooser();
    // 2. in a JFileChooser with a hacked setSelectedFile method, the
    // "File name:" text field is (appropriately) left alone.
    //JFileChooser chooser = new MyJFileChooser();
    //chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);  // = default anyway
    // show the Save dialog with a default file selected
    chooser.setSelectedFile( new File("dummyfile") );
    chooser.showSaveDialog(null);
  public static class MyJFileChooser extends JFileChooser
    //OVERRIDE
    public void setSelectedFile(File file)
      if ( !file.isDirectory() )
        super.setSelectedFile(file);
}

Similar Messages

  • JFileChooser filename field validation...

    All,
    I am embedding a JFileChooser object into my own JPanel. I'm setting the chooser to select directories only. The problem is that when I call chooser.getSelectedFile() and the user has typed something into the filename field, I only get the file that is selected in the list instead of the file entered by hand. Is there anyway to find out when the user changes the text in the file name field? Or, is there a way to force the selection in the list to update itself from the entered file name field? I know that if the user presses ENTER while in the file name field, this happens. Could I fake that somehow?
    Thanks!

    Well thank you all for your responces. I agree that there needs to be a change in the API to allow us to apply the changes in the file name text field. A simple solution could be to give us a method like JFileChooser.setFilenameField(JTextComponent filenameField). If the method isn't called then everything acts as it did before. If called, then you're own text field is used. Maybe an even more simple solution could be to have just a JFileChooser.getFilenameField() that returns a JTextComponent. This method could return null on UIs that don't use a filename text field.
    Anyway, digging into the BasicUI as a work-around seems to be enough for my purposes, however, this is an "after the fact" solution that doesn't let me change my "Next >" button state. I do popup an error now and then disable the "Next >" button. The previous behavior would just continue on without the user knowing that the texted they entered wasn't used.
    Thanks for your help!

  • Path and filename in footer

    If it is possible, how do I cause Acrobat 9 to report the current path and filename in the footer?
    Thanks!

    In a document-level JavaScript, add the following code, outside of a function definition:
    // Code in document-level JavaScript
    getField("PATH").value = path;
    where "PATH" is the name of a read-only text field that you've added to the bottom of each page.

  • Sort by Path and Filename - What does a guy have to do?

    Hello all,
    First post here and such, but as the title reads. I have been using iTunes since early versions of 7 when I aquired my used 2gen Mini.
    In a past incident where people were attaching viruses to the ID3 Tags (see: http://en.wikipedia.org/wiki/Talk:ID3#Virusesin_ID3tags) I took the liberty (stupidity) of stripping all my ID3 tags from my music directory due to that security fault at the time, but also because all of them (the tags) were horridly inputted to the files.
    As iTunes users we can see the bad mistake I made, so now when I add a folder/directory to iTunes they just get sent to the bottom of the iTunes 'music list'.
    'Sort by path and Filename' would do wonders in organization of these untagged files. When adding an entire genre or folder, all **** breaks loose and there are the typical 40 tracks of '01 - songname' '02 - songname' and so on.
    This is where the rant part comes in. Here we are on Version 7.4.3.1 and Apple still hasnt added this minute feature to iTunes.
    I have to use Yahoo! Musicmatch (yuck) to sort and rename my files, only then to re-import them back into iTunes. I dont really care for that software (yahoo) for anything except sorting. Because it adds the actual folder to the viewable list and allows for batch renaming of directories and ID3 Tag renaming of entire albums/directories. I am not so concerned over the actual filename itself, but at least sorting by Path in iTunes would be nice so that I could give the files their proper ID3 Tags.
    Cmon Cupertino, this one isnt that hard.
    Thank you for your time.
    6

    You have several options -- two of which I'll outline below (neither built-in to iTunes, sorry)
    1) Use an external program to write ID3 tags based on the path/filename. One such program is "MP3Tag" (http://mp3tag.de/en)
    2) I wrote a program that with put the path in the Description field. You select the playlist -- then for every track in the playlist it changes the Description to the path. NOTE: I do NOT recommend that you select the "Library" playlist because it will overwrite existing descriptions for TV Shows, podcasts, etc. You can limit it to music by selecting the "Music" playlist.
    EXE version:
    http://home.comcast.net/~teridon73/itunesscripts/itunespathdescription.zip
    source code:
    http://home.comcast.net/~teridon73/itunesscripts/itunespathdescription.pl
    If you use my program, and it works for you, please consider a Paypal donation at my home page (http://home.comcast.net/~teridon73/itunesscripts/)

  • "File Path and Name" field not displaying correctly

    Post Author: DaveWoo
    CA Forum: General
    Hello,Here's my situation: I'm currently upgrading from Crystal Reports for Visual Studio .NET 2003 to Crystal Reports for Visual Studio 2005. I have several reports (programmatically generated using VB.NET) that use the "File Path and Name" special field. Now, in the old version of Crystal Reports (2003), the field properly displayed the original file path and name; however, in the new version (2005), the field displays as "C:\DOCUME1\Username\LOCALS1\Temp\Filename{F2459406-3719-4C8B-917C-4A7055A18C76}.tmp" - in other words, the location of the temporary .rpt file.How do I get the "File Path and Name" field to correctly display the path & name of the original file, like it did in the prior version?- Dave

    This is a known issue tracked under ADAPT0000962216. At this time I do not know when this will be resolved, however Service Pack 2 for CR 2008 is targeted to be released by September and this may contain the fix.
    Ludek

  • JFileChooser.showSaveDialog() to be displayed along with calling screen

    hi,
    i have a frame ,in that i placed many components,one of the component is Jbutton,when the user click on this button ,it calls JFileChooser.showSaveDialog() to save a file in local system.
    After opening "file save window" , without clicking file save button ,if i open some other application(like WSAD,textpad) i am not able to see "file save window" until unless i search for that window by using "alt+tab".
    here what i am trying to say is "file save window " always needs to be on top of its calling screen.
    i even used JFileChooser .showSaveDialog(Component parent) ,but still that is not happening,if anyone come across this problem ,please help me.
    thanks in advance..

    hi PhHein,
    perfect answer.
    Thanks for your reply,your answer made me think on my code .There was small issue in my code and its been resolved now.

  • Adobe PDF Printer crashes when pasting in the filename field

    Greetings, first off there is no similar problem with any freeware pdf printers so I want to rule out my system config as being the culprit. This only happens in Adobe PDF.
    How to reproduce the problem? Have something in your clipboard and try to paste it into the filename field when printing the file as a pdf - you should have now crashed whatever you were trying to print and the program behind it.
    Please make a fix for this, it is ridiculous that I have to install a second, freeware, pdf printer because thousand dollar software is not working properly. And I have lost tons of receipts and work this way.

    I'm having a similar issue, on windows 7, 32 bit desktop system, using Windows Live Mail, with Acrobat X standard:
    Any time I try to "print to pdf" an email, just attempting to enter a file name for the pdf (no cut-and-paste), the dialogue box freezes, I can enter several characters, then the keyboard just freezes, the dialogue box becomes unresponsive. WLM ends up crashing. My work around is to not attempt to specify a name, just go with what Acrobat supplies, typically some thing like 00008.pdf. Then edit the name, and/or location, within Windows Explorer.
    I've tried repairing the install, believe that actually worked, a few months back. Tried again today when the problem cropped up again, but repairing the install didn't help.
    This has been ongoing for me for some months now. Not situation normal. Don't want to be snippy, but seems like tech support response is VERY slack...

  • DSO - What key fields and data fields in dso

    Hi experts,
    I need to create a dso in between the cube and 2 data sources(2lis_11_vaitm, 2lis_12_vcscl) to stage the data. My question is: what key fields and data fields to choose for the dso? is there a standard dso to copy? please explain in detail the model to set up, whether to connect both the ds's to dso and then to cube or one ds to dso and the other to the cube. more details will help.

    Check this for standard DSO:
    http://help.sap.com/saphelp_nw04/helpdata/en/43/fcdc387f34384f94c3227baf3837a8/content.htm
    Thanks...
    Shambhu

  • Infoset Join condition on Key feilds and data fields

    Hi Guys,
    I have a requirement to biuld the Info set with join conditon on two DSO's  the info objects which i am using in the JOin condition are defined as data fieds in one DSO and defined as key fields in another DSO, is it possible to define join condition on key fields and data fields.
    The two info objects are                
                           0AC_DOC_NO
                           0ITEM_NUM
    These two info objects are defined as  data fields in DSO :   0LIV_DS1   Invocie verificaion
                                                            key fields in DSO:    0FIAP_0o3 FI AP Line Item
    Please suggest me is it possible to define join the condtion on the data fields and key feilds.
    Thanks
    Best regards
    SG

    Hi
    yes you can create join, you will get any issue in reporting level.
    example: Say i want to create Info Set on 0MATERIAL and Sales DSO.
    In 0MATERIAL Info Object it is key filed, but in my DSO 0MATERIAL is data field.Still we can create
    Creation of join is dependent on fields common in your source objects.
    check out the below document
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/2f5aa43f-0c01-0010-a990-9641d3d4eef7?QuickLink=index&overridelayout=true
    Regards,
    Venkatesh
    Edited by: Venkateswarlu Nandimandalam on Sep 27, 2011 2:26 AM

  • Key fields and data fields in a DSO  ??

    i have a question regarding key fields and data fields in a Standard DSO...
    i am using 2 datasources to build a open sales report 2LIS_11_VASTH  and  2LIS_11_VASTI   i am pulling in data from these 2 data sources to a DSO and i am wondering what infoobjects should be in the key fields and data fields .....does this reflect back to table VBUK and VBUP tables and does the key field in the DSO have to be the key fields in VBUK and VBUP tables  ????  or what really should be included as key fields and data fields   ????  
    please help....

    If you look at the various SD tables, VBELN and POSNR are commonly used as the document number and document line item.
    For VBAP and VBUP, it's referring to the Sales Order Line Item with the columns VBELN and POSNR as the key for both tables. However, if you look at the LIPS table, which is the Delivery Line Item table, it too has VBELN and POSNR as the key. Likewise, the VTTP table, which is the Shipment Line Item table, also has VBELN and POSNR as the key.
    While using RSOSFIELDMAP as a map is a fairly good "rule of thumb", it still needs to be used with a level of skepticism.

  • Prerequsites for deciding Key fields and data fields

    Hi
    I would like to know the criteria to decide upon KEY fields and Data fields for an infoprovider.

    Hi,
    What is a Key field in a Database and How should I choose one?
    Keys are crucial to a table structure for many reasons, some of which are identified below:
    They ensure that each record in a table is precisely identified.
    They help establish and enforce various types of integrity.
    They serve to establish table relationships.
    Datafields may be Charecteristics and it may be keyfigures
    Regards,
    Marasa.

  • Key Fields and Data Fields in ODS

    Hi Guru's ,
    Can u Explain what are Key Field's and Data Field's in ODS,and How they work.
    Thanx in Advance.

    Hi Pradeep,
    An ODS’ key fields forms a unique combination of chars according to which data in the ODS will be summed up. Data fields are additional fields, chars or key figures.
    For example, you have the following key fields:
    Doc No, Doc line item (item no in the doc) and you load the following data:
    Doc# Item# Amount CALDAY
    1234  1        100       26.09.2005
    1234  1        150       27.09.2005
    1234   2        300      27.09.2005
    1235   1        400      27.09.2005
    The first two rows with the same key fields (1234-1) will be aggregated and into ODS will go amount of 250.
    What I said is true if for Amount key figure the ‘Add’ option is set.
    But if you set an ‘Overwrite’ option, then the second record will overwrite the first one and only amount of 150 will go to ODS!
    But if CALDAY is also a key field, then into ODS will go all records without any aggregation, because key fields combination is different for all records.
    So, ODS’ key fields choice and KFs settings are very important for data aggregation in the ODS.
    Best regards,
    Eugene

  • Data fields and key fields

    Hi,
    Data fields and key fields are same as Characteristcs and key figures? Or they are diffrerent?
    Thanks,
    Radha

    HI
    Key Fields =  Acts as Primary Key for The ODS like Primary of Tables in R3.
    Data fields =  Apart from Key fields We consider rest as data fields.
    Ususally we use Characteristic info Objects and Dates in Key Fields and Key figures in Data fields.
    It's decisive factor for overwriting property of ODS or DOS.
    Hope this helps.
    Regards,
    Rangzz
    Edited by: Ranganath Kodiugane on Feb 7, 2009 12:14 PM

  • Chart report Condition fields and Data fields

    Hi all,
    i have tried chart report by adding two condion fields and one data field, the report is more meaning full in this scenario. the first condition field is taken as x-axis, the 2nd condition fields is taken as legend.
    while adding more condition fields and data fields, i feel its not showing meaningfull data.
    can anyone explain how the condition fields and data fileds are manipulated by crystal report.
    i am using CR XI R2 Server.
    Thanks
    Padmanaban V

    i am using Crystal Report XI R2 RAS Embedded in my server.
    as we can add any number condition fields programatically using the method
    ConditionField.Add(FieldObj), i would like to know how these fields are manipulated internally by the RAS server.
    that means, what is the significance of condition fieldobject 1, condition fieldobject 2,condition fieldobject 3 etc...
    if i add more than two condition fields , RAS Chart Report always returns 0 as legend value for all legends.
    Thanks in advance
    Regards,
    Padmanaban V
    Edited by: Padmanaban Viswanathan on Dec 22, 2008 9:53 AM

  • Identify key fields and data fields

    Hi
    i have datasource 0co_om_cca_9 .
    i want build 1 DSO, how can i identify what are key fields and data fields to build DSO based on that datasource.

    Hi sunnel,
    The DSO are like 2-D database tables.
    We use the technical keys here in counterpart to the business keys in Infocubes.
    The key fields are the one based on which the records are identified uniquely in the database table.
    And the data fields are the ones which are aggrgated or summarised or overwritten based on the value in key filed.
    For example:
    The ID no.s of the employees will be unique and it can be used as a key field.
    The feilds like the Salary taken by the employee every month :"SALARY"
    and the no. of leaves they taken: " NO. OF LEAVES" can be used as data fields.
    So that the salary or the leaves taken by a particular employee can be aggregated based on her/his ID no.
    The key fields in DSO doesnty mean Key figures.The key field means any unique key or a key based on which the records are sorted in the DSO
    And key figures are the data fields.Some of the Characteristics can also be data fields in DSO.
    Please give points if u r satisfied wit the information
    Also let me know if u hav any doubt and if any thing is wrong.
    Regards,
    Kalpana M

Maybe you are looking for