How to display computer files and folders in java swing GUI [duplicate]
Possible Duplicate:
Swing JTree with Checkbox and JFileChooser
I am developing an application in java swings.I have used jfilechooser to open up the files and directories in my computer.But the structure of the directories and files in jfilechooser are not the way i wanted.I wanted it this way
How can i achieve this?Any suggestions would be really 开发者_如何学Chelpful.Thanks in advance.
a TreeCellRendererYou will need to use a JTree. You can build your own data structure of nodes, organize them how you see fit, then render them with a TreeCellRenderer.
To display the correct icons I suggest to use javax.swing.filechooser.FileSystemView
Here are some classes I wrote to create a list and a combo box of file system roots:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JFileRootList.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JFileRootComboBox.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/filechooser/FileRootComboBoxModel.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/filechooser/FileRootCellRenderer.html
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/CellRenderer.html
To use the library you can use the following Maven dependency:
<dependency>
<groupId>org.softsmithy.lib</groupId>
<artifactId>lib-core</artifactId>
<version>0.1</version>
</dependency>
Or download it from here: http://sourceforge.net/projects/softsmithy/files/softsmithy/v0.1/
Here is the source:
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/main/java/org/softsmithy/lib/swing/JFileRootList.java
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/main/java/org/softsmithy/lib/swing/JFileRootComboBox.java
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/main/java/org/softsmithy/lib/swing/filechooser/FileRootComboBoxModel.java
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/main/java/org/softsmithy/lib/swing/filechooser/FileRootCellRenderer.java
http://softsmithy.hg.sourceforge.net/hgweb/softsmithy/lib/main-golden/file/5c4db802573b/lib-core/src/main/java/org/softsmithy/lib/swing/CellRenderer.java
精彩评论