File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes JfileChooser save without a dialog box popping up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JfileChooser save without a dialog box popping up" Watch "JfileChooser save without a dialog box popping up" New topic
Author

JfileChooser save without a dialog box popping up

nuala finnegan
Greenhorn

Joined: Jun 15, 2012
Posts: 5
Hi,

I was wondering if anyone can help. I have an application that has a text field I want to use Jfilechooser to save or save As the data.

If the file already exisits i want the end user to be able to hit save without the dialog box popping up asking for a file name folder etc, like it would in MS Word etc..

Is this possible?

I'd really appreciate any help

Thanks

Nuala
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It isn't clear to me what you want. You've told us some things you don't want, but not what you do want.

So: Do you want a JFileChooser, but built into your GUI instead of in a popup dialog?

Or do you just want the user to key the full path to the output file into a text field instead of letting them find it via a JFileChooser?

You said "If the file already exists" but I couldn't tell what file that was or how the code would know about it.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Wait a minute... you mentioned the way MS Word works, in other words you want to save the data in the same file it was loaded from?

If that's the question, then sure. When you load the data from a file, save the file's path in a variable somewhere. Then use that variable as the name of the file when you go to save the data.
nuala finnegan
Greenhorn

Joined: Jun 15, 2012
Posts: 5
Hi Paul,

Thanks very much for responding... Sorry the request is a bit crytic... I want the application to work like word.. So a user can open a file edit it and save it..
Or they can create a new file from scratch... If they edit an existing file i want them to be able to just hit save and I can do like you said to save the file name etc..

However, how do I prevent the dialog box from popping up? Like in for eg word you can just hit the save icon etc and nothing pops up...
This is my code, quite basic!!!

Thanks

Nuala

int returnVal1 = chooser.showSaveDialog(this);

if(returnVal1 == JFileChooser.APPROVE_OPTION) {

chooser.getSelectedFile().getPath());
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You just remove that code. Remember, a JFileChooser is just what its name says, a thing for choosing a file. You already have the name of the file you want to save to, so you can skip the step which displays the JFileChooser and go directly to the code which saves the data in the file with that name.
nuala finnegan
Greenhorn

Joined: Jun 15, 2012
Posts: 5
oh yeah (I'm being dim!)... thanks very much!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JfileChooser save without a dialog box popping up
 
Similar Threads
java script error
Store a file to Hard Disk from a Servlet
File Chooser Dialog Boxes
How to avoid open/Save dialog box while downloading?
disposing SAVE file dialog its urgent