• Post Reply Bookmark Topic Watch Topic
  • New Topic

help JFileChooser--about overwrite file  RSS feed

 
Eric lau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a JFileChooser.showSaveDialog(this) to choose the file when I want to save one file,if the file i choosed exist,I want to ask question as "will you overwrite file XXXX",but ,JFileChooser can't show thie dialog,what can I do for this?
help!
 
Mahesh swami
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can check if the file exists in the current directory by file.exists() method and then show a JOptionPane.showMessageDialog() or JOptionPane.showConfirmDialog().I think this should work.
 
Eric lau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes ,i have do so ,and it work.
But when the confirm appear,the JFilrChooser diolag disappear,I see the source code of JFileChooser,when it sumit it setvisiable(false).
 
Thorsten Schenkel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can overwrite the method approveSelection of JFileChooser.
Example:

regards
Thorsten
 
Eric lau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah!it work!thank!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!