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
2010-08-25 20:27:14
"I intend to populate a JFileChooser with **names from a database** but use the standard JFileChooser "
TheLQ
2010-08-25 21:45:25
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
2010-08-25 20:29:51
Or just overload most of the useful methods in JFileChooser. If important files are final, then just copy the source
TheLQ
2010-08-25 21:46:26
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
2010-08-25 21:49:58