Exemplo n.º 1
0
  private void changeDirectory(File dir) {
    JFileChooser fc = getFileChooser();
    // Traverse shortcuts on Windows
    if (dir != null && FilePane.usesShellFolder(fc)) {
      try {
        ShellFolder shellFolder = ShellFolder.getShellFolder(dir);

        if (shellFolder.isLink()) {
          File linkedTo = shellFolder.getLinkLocation();

          // If linkedTo is null we try to use dir
          if (linkedTo != null) {
            if (fc.isTraversable(linkedTo)) {
              dir = linkedTo;
            } else {
              return;
            }
          } else {
            dir = shellFolder;
          }
        }
      } catch (FileNotFoundException ex) {
        return;
      }
    }
    fc.setCurrentDirectory(dir);
    if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES
        && fc.getFileSystemView().isFileSystem(dir)) {

      setFileName(dir.getAbsolutePath());
    }
  }
Exemplo n.º 2
0
  public JFileChooser createFileChooser() {
    // create a filechooser
    JFileChooser fc = new JFileChooser();
    if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) {
      fc.setDragEnabled(true);
    }

    // set the current directory to be the images directory
    File swingFile = new File("resources/images/About.jpg");
    if (swingFile.exists()) {
      fc.setCurrentDirectory(swingFile);
      fc.setSelectedFile(swingFile);
    }

    return fc;
  }
 public static void main(String[] args) {
   chooser = new JFileChooser();
   chooser.setCurrentDirectory(new File("."));
   PersistentFrameTest test = new PersistentFrameTest();
   test.init();
 }
Exemplo n.º 4
0
 public void actionPerformed(ActionEvent e) {
   JFileChooser fc = getFileChooser();
   fc.setCurrentDirectory(fc.getFileSystemView().createFileObject(getDirectoryName()));
   fc.rescanCurrentDirectory();
 }
Exemplo n.º 5
0
 /** Apply default folder to file chooser */
 public void applyDefaultFolder(final JFileChooser fileChooser) {
   fileChooser.setCurrentDirectory(getDefaultFolder());
 }