How to pre-populate a JFileChooser will “filename”?

六月ゝ 毕业季﹏ 提交于 2020-01-15 06:17:29

问题


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


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/3569807/how-to-pre-populate-a-jfilechooser-will-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!