java JFileChooser default name

Discussion in 'Java' started by SV, Oct 29, 2004.

  1. SV

    SV Guest

    Hello,

    I 'm writing a program in which I should be able to open and save files.
    The problem is:
    when I open a file, then create a new file and try to save this new file,
    the save dialog window still suggests the name of that previous file.
    This may seem like a detail, but I think you can easily overwrite your
    previous file this way ...
    So I 'd like to either set a default filename when using "save as", or let
    the dialog window suggest no filename at all...

    setSelectedFile(null) or setSelectedFile(default) doesn't seem to work ...

    Does anyone have an idea how I can do this?

    Thanks!

    Stephanie
     
    SV, Oct 29, 2004
    #1
    1. Advertising

  2. SV

    Alex Hunsley Guest

    > Hello,
    >
    > I 'm writing a program in which I should be able to open and save files.
    > The problem is:
    > when I open a file, then create a new file and try to save this new file,
    > the save dialog window still suggests the name of that previous file.
    > This may seem like a detail, but I think you can easily overwrite your
    > previous file this way ...
    > So I 'd like to either set a default filename when using "save as", or let
    > the dialog window suggest no filename at all...
    >
    > setSelectedFile(null) or setSelectedFile(default) doesn't seem to work ...
    >
    > Does anyone have an idea how I can do this?
    >
    > Thanks!
    >
    > Stephanie


    Strange. The JavaDocs for JFileChooser say:

    getSelectedFile

    public File getSelectedFile()

    Returns the selected file. This can be set either by the programmer
    via setFile or by a user action, such as either typing the filename into
    the UI or selecting the file from a list in the UI.

    Returns:
    the selected file
    See Also:
    setSelectedFile(java.io.File)


    ... but I can't find the actual setFile() method mentioned in the docs...

    alex
     
    Last edited by a moderator: Oct 4, 2009
    Alex Hunsley, Oct 29, 2004
    #2
    1. Advertising

  3. >> setSelectedFile(null) or setSelectedFile(default) doesn't seem to work ...

    Does the second 'seem' to compile?
    <http://www.physci.org/codes/javafaq.jsp#exact>

    >> Does anyone have an idea how I can do this?

    ....
    > Strange. The JavaDocs for JFileChooser say:

    ...
    > .. but I can't find the actual setFile() method mentioned in the docs...


    I think they meant JFileChooser.setSelectedFile(java.io.File)
    but made a typo.

    OTOH, to the OP. Have you considered setting the selected file to
    ".", or "new01.txt"?

    You can also check for the file's existence when you go to write
    it, if it exists, ask the user to confirm.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Last edited by a moderator: Oct 4, 2009
    Andrew Thompson, Oct 29, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green
    Replies:
    0
    Views:
    731
    Roedy Green
    Jul 9, 2003
  2. Alex Schonlinner

    Java WebStart and JFileChooser

    Alex Schonlinner, Feb 27, 2004, in forum: Java
    Replies:
    0
    Views:
    541
    Alex Schonlinner
    Feb 27, 2004
  3. Alan
    Replies:
    4
    Views:
    5,112
  4. Allen
    Replies:
    6
    Views:
    8,559
    Mean Mike
    Sep 18, 2013
  5. Ramon F Herrera
    Replies:
    3
    Views:
    481
    Ramon F Herrera
    Nov 13, 2007
Loading...

Share This Page