开发者

Swing: JFileChooser with favorites?

开发者 https://www.devze.com 2022-12-19 15:16 出处:网络
I\'m working on an application which needs to select files. JFileChooser is a great start, but I ne开发者_如何学编程ed to augment it. I can start it at one particular directory with JFileChooser.setCu

I'm working on an application which needs to select files. JFileChooser is a great start, but I ne开发者_如何学编程ed to augment it. I can start it at one particular directory with JFileChooser.setCurrentDirectory(), but how can I offer the user a "favorites" functionality, either in terms of favorite files saved for later, or favorite directories to jump to?


While the JFileChooser accessory was intended to be used for things like thumbnails of the currently selected file, per the JavaDocs:

An accessory is often used to show a preview image of the selected file; however, it can be used for anything that the programmer wishes, such as extra custom file chooser controls.

So you'll have to create a custom JComponent to represent "favorite directories", then call setAccessory(myFavesComponent) on your file chooser.

To actually implement the storage of favorite directories, you'll want to use the Preferences API.


There are already some libraries in Java of "favorites" feature, you can use, for example, this one.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号