Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java JFileChooser default name

Reply
Thread Tools

java JFileChooser default name

 
 
SV
Guest
Posts: n/a
 
      10-29-2004
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


 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      10-29-2004
> 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 Ian; 10-04-2009 at 04:54 PM..
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-29-2004
>> 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 Ian; 10-04-2009 at 04:54 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remove JFileChooser default accept all file filter? Allen Java 6 09-17-2013 11:12 PM
Need to modify JFileChooser's default behavior Ramon F Herrera Java 3 11-13-2007 04:58 AM
JFileChooser File Name Restrictions Alan Java 4 07-19-2004 05:47 AM
Java WebStart and JFileChooser Alex Schonlinner Java 0 02-27-2004 03:04 PM
Re: java getPath getAbsolutePath getCanonicalPath and JFileChooser reuse Roedy Green Java 0 07-09-2003 08:31 PM



Advertisments