This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JFileChooser saving removes default file name when a directory is selected  RSS feed

 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application I have JFileChooser that is used to save a data file. The file does get saved, etc.

The problem is that the file gets a default filename in the File name box (this is correct), but as soon as a directory is selected, the filename is replaced with the path of the directory.

I suspect the fix is a simple one, but I just can't figure it out.

Thanks for your help!

EDIT: This looks like the old Java bug 4357012 (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4357012). They say it's fixed, and I'm using Java 6, so this should not be the issue, right?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the behavior you describe. To get better help sooner, post a SSCCE that shows the problem.
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ironically, in making an SSCCE, I was able to solve my problem.

I had forced setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES). When I removed this, it worked fine.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Gallant wrote:Ironically, in making an SSCCE, I was able to solve my problem.

Actually, that's not ironic at all. One of the expected possible outcomes of making an SSCCE is that you will stumble over the answer while doing that.
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The system woks!

Let this be a lesson for all posters!

Make an SSCCE before posting your question, the time you save may be your own!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!