When using a JFileChooser there is a "Details View" button. There are 5 pieces of information displayed per file. Icon, Name, Size, Type, and "Date Modified". What class controls the 'Type' value? Using the c开发者_运维百科lass 'FileView', the Icon and Name can be controlled. Using the class 'File', the Size and "Date Modified" can be controlled. The type descriptions are very good and I would like to use them in other places, also I have some "New" types that I would like to be able to give a "Type" description to.
FileView>>getTypeDescription()
http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/filechooser/FileView.html#getTypeDescription%28java.io.File%29
Is this what you are looking for?
import javax.swing.*;
import javax.swing.filechooser.*;
import java.io.*;
public class A {
public static void main(String[] args) {
File f = new File("f.jpg");
JFileChooser j = new JFileChooser();
System.out.println(j.getTypeDescription(f));
}
}
The output is on my system:
F:>javac A.java
F:>java A
IrfanView JPG File
This is because i have IrfanView installed on my system; JFileChooser/FileView>>getTypeDescription() queries the system (in my case Windows) for this information. To "add your own descriptions" you can (like camickr said) override getTypeDescription() or you can add it to your system (in the case of Windows in the registry under HKEY_CLASSES_ROOT).
I think what you have to do to override the type-information in Java is instantiate JFileChooser with your own subclass of FileSystemView.
subclass FileSystemView to MyFileSystemView
override getSystemTypeDescription(File f)
in that overrride for your special file-type return whatever you want and return the default-value by returning the value from using a super-call otherwise
instantiate your FileChoosers with one of the following prototypes, giving your custom MyFileSystemView as second argument
JFileChooser(File currentDirectory, FileSystemView fsv)
JFileChooser(String currentDirectoryPath, FileSystemView fsv)
精彩评论