walters
walters

Reputation: 1467

How to pre-populate a JFileChooser will "filename"?

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).

Upvotes: 2

Views: 1297

Answers (2)

todeyius
todeyius

Reputation: 52

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.

Upvotes: 1

camickr
camickr

Reputation: 324118

JFileChooser chooser = new JFileChooser()
chooser.setSelectedFile(new File("c:/yourPath/someFile") );

Upvotes: 2

Related Questions