views:

62

answers:

2

I intend to populate a JFileChooser with names from a database but use the standard JFileChooser Dialog for load, delete, save and save-as. I want to give users an impression that they are working on a file system whereas am using a database at the backend to save changes. The user should not be able to browse to a different directory to save or save as. I want to use the same JFileChooser Dialog but with a cancel button and another button(delete|save|save as|load).

A: 
JFileChooser chooser = new JFileChooser()
chooser.setSelectedFile(new File("c:/yourPath/someFile") );
camickr
"I intend to populate a JFileChooser with **names from a database** but use the standard JFileChooser "
TheLQ
A: 

Can't be done using the JFileChooser.

JFileChooser only operates on java.io.File's. To do this you would have to subclass java.io.File and create some kind of fake file system that would be very ugly.

You are going to have to make your own save dialog component or find another similar component to use. JFileChooser isnt what you want.

todeyius
Or just overload most of the useful methods in JFileChooser. If important files are final, then just copy the source
TheLQ
Yes it can be done using `JFileChooser`, by extending `File` and `FileSystemView`. That's how virtual folders like "My Computer" under Windows are represented in a `JFileChooser`. Call it ugly if you want but it's not as ugly as implementing a custom open/save dialog.
finnw