-5

I would like to know the difference between showOpenDialog() and showSaveDialog() methods in the JFileChooser.

What I found is the change in the title and the text of the approve button. Nothing seemed to be a difference. They can be set by using setDialogTitle() and setApproveButtonText() respectively. But what is the reason behind the existence of two of these methods when they can be carried out normally.

Please don't answer about the difference between open and save. Rather, I would like to know the reason behind those two methods. Also don't answer You ask the swing team or any other similar answer.

They seem to be internally using showDialog(), I can use it because it is public. And for both dialogs I am able to get the selected file(s).

I feel there is no difference. I would like to here opinions of others.

Aaron
  • 992
  • 3
  • 15
  • 33
JavaTechnical
  • 8,846
  • 8
  • 61
  • 97
  • @Downvoter, could you say me the reason why this post was down voted? – JavaTechnical Jul 14 '13 at 16:27
  • 1
    you're question is probably being downvoted for several reasons... Because the answer is kind of obvious (why would you get rid of one if you've got to change the other to get the functionality back), because you're asking for opinions not answers, and because of your somewhat 'cocky' phrasing in your question etc. – Andy Jul 14 '13 at 16:45
  • I think i couldn't here any answers except what i have done. I am deleting. – JavaTechnical Jul 14 '13 at 16:47
  • There's no reason for you to delete the entire question, just accept the answer you have and move on. Learn from this experience! Generally, questions on StackExchange sites should fit the Q&A style and have clear answers, rather than 'opinions'! Also, please review your English, seeing as though this is an English site - I can't really understand what you mean by that last comment! – Andy Jul 14 '13 at 17:39
  • What do you mean the answer is not correct? You're the one asking the question, if you know the full answer then "answer your own question"! The answer is correct anyway - see my comment on it. – Andy Jul 15 '13 at 10:34

1 Answers1

4

ShowSaveDialog let's you create a new file (browse to folder, then type in desired filename), ShowOpenDialog makes you choose a pre existing file (browse to location and choose a file that is already there, you can still choose to delete/overwrite selected file)

Epicblood
  • 1,167
  • 2
  • 10
  • 29
  • But with both of them i am able to open as well as save. It just depends on the handler we write for the approve button. – JavaTechnical Jul 14 '13 at 13:57
  • with the open dialog you cannot ask the user for a file name, they could just overwrite an existing file, as no new file name could be specified. whereas with the save dialog, the user could enter an inexisting file name to be opened... – cello Jul 14 '13 at 14:02
  • They could not only choose an existing file with open dialog, they could also create a new file. – JavaTechnical Jul 14 '13 at 14:13
  • @JavaTechnical Why would you ask your users to create a new file to save to, and then select it in an open dialog, when you can do everything from the save dialog!? The two methods simply exist for the ease of both the programmer, and the end user – Andy Jul 15 '13 at 10:37
  • Who knows it is open dialog, that is what i said in the question, we can simply call setDialogTitle() to change the title and setApproveButtonText() to change the text to save! :) – JavaTechnical Jul 15 '13 at 10:41
  • 2
    Sorry about not responding for so long, was gone. Anyway, if you just change the title & text, it is not the same, `showOpenDialog()` requires the file to already exist, `showSaveDialog()` does not. – Epicblood Jul 29 '13 at 23:36