FileDocCategorySizeDatePackage
JavaChooserWithPreview.javaAPI DocExample827Sun Mar 28 19:08:36 BST 1999None

JavaChooserWithPreview.java

import java.io.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import com.macfaq.swing.filechooser.*;
import com.macfaq.io.*;


public class JavaChooserWithPreview {

  public static void main(String[] args) {
    
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new JavaFilter());
    fc.setAccessory(new TextPreview(fc));
    int result = fc.showOpenDialog(new JFrame());
    if (result == JFileChooser.APPROVE_OPTION) {
      try {
        File f = fc.getSelectedFile();
        if (f != null) {
          FileInputStream fin = new FileInputStream(f);
          StreamCopier.copy(fin, System.out);
          fin.close();
        }
      }
      catch (IOException e) {
        System.err.println(e);
      }
      
    }
    
    System.exit(0);

  }
  
}