This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

New File Dialog in JFileChooser  RSS feed

 
ManChun Lam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In SaveDialog under JFileChooser, there is an item "New Folder" on the context menu (when you right-click). Is there an easy way to add "New File" to that context menu? Thank you.

ManChun Lam
 
Paul Clapham
Sheriff
Posts: 22678
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

There might be a difficult way, but I don't know what that might be.

I haven't ever seen such a button in Save dialogs which I have used. (Perhaps that's why the option isn't there.) What would it do, if it were there?
 
ManChun Lam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. This is what I want to do,

1. Browse the file system for a file
2. If no file can be found, make a file at the current "browsing" directory
3. Select the file, use getSelectedFile() to return a File to my background application

The reason I chose JFileChooser is so that I don't have to code the "browse" dialog again.

Thank you.

ManChun Lam
 
Paul Clapham
Sheriff
Posts: 22678
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ManChun Lam wrote:1. Browse the file system for a file
2. If no file can be found, make a file at the current "browsing" directory
3. Select the file, use getSelectedFile() to return a File to my background application

That's actually what the JFileChooser allows the user to do. The user can navigate around the file system and choose a file. (You have used that sort of dialog yourself, surely?) Or if there is no file the user wishes to choose, the user can type the name of a new file in the box provided for that. It's not clear to me how your requirements differ from that.
 
ManChun Lam
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you said is indeed correct. My goal is to make it more intuitive.

Consider an average computer user, if they cannot find their file, they will try to create it. And I think, most probably, they will do the following,

1. Right-click to see if "New > File" exists
2. Put in file name, it shows up in the dialog
3. Select it
4. Click Save

I am taking this from how Windows Explorer works. Since I see there is "New Folder" under the context menu in JFileChooser, I figure I could put in "New File" as well. Thank you.

ManChun Lam
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No offence, but if that's what you think an "average computer user" will think, well then you're a less than average computer user yourself.

The way to create a new flie to save content has always (since graphics interfaces began) been to type a file name and click "Save"

According to your strategy, what would be the result of a user sleecting "New File" multiple times and clicking "Cancel" or closing the dialog? of the user sleecting "New File" and then selecting another, pre-existing file before clicking "Save"?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!