aspose file tools*
The moose likes I/O and Streams and the fly likes File Chooser Dialog Boxes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File Chooser Dialog Boxes" Watch "File Chooser Dialog Boxes" New topic
Author

File Chooser Dialog Boxes

Jeffrey Smith
Greenhorn

Joined: Aug 21, 2004
Posts: 4
What I want to do is have a JFileChooser Save Dialog box to select the destination and file name of the file I will save. I have never worked with these before, but I am trying to figure them out.

Right now, I have it so I can open up the dialog box and choose where I want to save it and what to call it, this works fine, but what I want to do is have it so that the existing file name and directory and file name (the one I want to have set by default) is where the dialog box opens up to. for example:
if the file name is bob.txt in the C:\ directory, wheN I push the button to open the dialog box, the box pops up and is in the C:\ directory, it has "bob" in the file name box, and has the ".txt" selected in the file type combo box. how would I do this?

I know this may seem rather simple for some of you, but I dont know of any resources to help me figure this out (I dont have a Java book that covers this, and java.sun.com explanations only leave me confused.
if you could help me, or better yet give a link to a good tutorial (not java.sun.com) so that I could solve my own problems in the future, that would be great, thanks.
Pat Hays
Ranch Hand

Joined: Aug 20, 2004
Posts: 138
before opening the dialog, try this code, should be working.

fileChooser.setSelectedFile(youFile);
[ August 31, 2004: Message edited by: Pat Hays ]

Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
Jeffrey Smith
Greenhorn

Joined: Aug 21, 2004
Posts: 4
OK that works, I was sure exactly what the file in parenthsis was supose to be, but I figured it out.




New Question:
after the user selectes the file name they want and file type (.txt for example), and click on the save button, how can I get the extention that they selected from the file type combo box, right now when I go and get the file name and directory, I dont have the extention .txt in it unless the user included it there themsleves.

and also, if the filename already has a txt extention on it, how can I make the txt extention file type select itself from the file type list, and not go by default to the top one on the list.
 
Consider Paul's rocket mass heater.
 
subject: File Chooser Dialog Boxes