I am new to Java progamming and am building a application that will add, display and remove files from a given folder location.
I have added files using JFileChooser and know how to delete the files. However I am stuck with the display portion.
I want to display the files and folder using different icon inside my application. I tried to add a JFileChooser inside the display panel and disable the button and menu components of the dialog box, but I have not succeeded. Is there any better way to do this?
I prefer the following way.
Calling this code will cause a
JFileChooser
to popup in its own window.I usually call it from within a
JButton
'sActionListener
code.I've never fully replicated a file browser. I have displayed files in list/tables using the icon that is provided by your platform. This is rather easy to do with the help of FileSystemView. Use the getSystemIcon(File) method to retrieve the correct icon. Then you can build a JList/JTable of files using this icon.
If you don't need all the flexibility of
JFileChooser
, you should usejava.awt.FileDialog
instead. Your OS X users will thank you.FileDialog
uses a native file chooser window, whileJFileChooser
is a swing component, and lacks keyboard shortcuts and other niceties.