A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
Save as dialog box question
Antigoni Splash
Greenhorn
Joined: Jun 12, 2009
Posts: 10
posted
Jun 15, 2009 08:15:37
0
I have a simple save dialog box as follows:
int returnVal = fc.showSaveDialog(GuiKiprosJob1.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); File fileChosen = file.getAbsoluteFile(); }
One question!
I want when the save dialog opens a default filename to appear in the File Name field for example "Hello.txt".
Anyone knows how to do it?
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
Jun 15, 2009 09:31:10
0
javax.swing.JFileChooser
You retrieve the selected file using getSelectedFile(). I'll leave it to you to find the method that sets the selected file
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
Antigoni Splash
Greenhorn
Joined: Jun 12, 2009
Posts: 10
posted
Jun 16, 2009 01:52:22
0
I' ve tried that beforing posting but i didn't have success i don't know if i am using the command in a wrong way...
I am using the following command:
JFileChooser fc = new JFileChooser(); fc.setSelectedFile(new File("Hello.txt"));
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
Jun 16, 2009 01:57:44
0
That works just fine for me. What is not working with that code?
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
I like...
posted
Jun 16, 2009 02:32:24
0
The file needs to exist in the currently displayed location to be selected
[
Donate a pint, save a life!
] [
How to ask questions
] [
Onff-turn it on!
]
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
Jun 16, 2009 02:58:27
0
No it doesn't. How else could you save to new files?
Antigoni Splash
Greenhorn
Joined: Jun 12, 2009
Posts: 10
posted
Jun 16, 2009 03:31:41
0
The file doesn't have to exist i was just placing the command in a wrong place!
Thanks!
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
I like...
posted
Jun 16, 2009 04:01:17
0
Rob Prime wrote:
No it doesn't. How else could you save to new files?
Oh! Its a save dialog. My bad. You are correct.
Teaches me not to skim over the surface
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: Save as dialog box question
Similar Threads
Open Dialog JFileChooser
Use of JFileChooser
JFileChooser in an applet
disposing SAVE file dialog its urgent
Download dialog box
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter