javax.swing.JFileChooser.setCurrentDirectory()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中javax.swing.JFileChooser.setCurrentDirectory()方法的一些代码示例,展示了JFileChooser.setCurrentDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFileChooser.setCurrentDirectory()方法的具体详情如下:
包路径:javax.swing.JFileChooser
类名称:JFileChooser
方法名:setCurrentDirectory

JFileChooser.setCurrentDirectory介绍

暂无

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

private static JFileChooser createFileChooser() {
 final JFileChooser chooser = new JFileChooser();
 //  sets up default file view
 try {
  chooserFile = new File((new File(".").getCanonicalPath()));
 } catch (Exception e) {
  // go with current directory.
 }
 chooser.setCurrentDirectory(chooserFile);
 chooser.addActionListener(e -> {
  if(e.getActionCommand().equals("ApproveSelection")) {
   chooserFile = chooser.getSelectedFile();
  }
 });
 chooser.setMultiSelectionEnabled(true);
 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
 return chooser;
}

代码示例来源:origin: deathmarine/Luyten

private void retrieveSaveDialogDir(JFileChooser fc) {
  try {
    String currentDirStr = luytenPrefs.getFileSaveCurrentDirectory();
    if (currentDirStr != null && currentDirStr.trim().length() > 0) {
      File currentDir = new File(currentDirStr);
      if (currentDir.exists() && currentDir.isDirectory()) {
        fc.setCurrentDirectory(currentDir);
      }
    }
  } catch (Exception e) {
    Luyten.showExceptionDialog("Exception!", e);
  }
}

代码示例来源:origin: cmusphinx/sphinx4

static public void getFilename(String title, int type) {
  int returnVal;
  fileChooser.setDialogTitle(title);
  fileChooser.setCurrentDirectory(file);
  fileChooser.setDialogType(type);
  if (type == JFileChooser.OPEN_DIALOG) {
    returnVal = fileChooser.showOpenDialog(jframe);
  } else {
    returnVal = fileChooser.showSaveDialog(jframe);
  }
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    file = fileChooser.getSelectedFile();
    filename = file.getAbsolutePath();
    prefs.put(FILENAME_PREFERENCE, filename);
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args){
  JFileChooser chooser = new JFileChooser();
  chooser.setCurrentDirectory(new File("D:\\outlook"));
  chooser.showSaveDialog(null);
}

代码示例来源:origin: chewiebug/GCViewer

@Override
public void actionPerformed(final ActionEvent e) {
  final GCDocument gcDocument = gcViewer.getSelectedGCDocument();
  for (int i=0; i<gcDocument.getChartPanelViewCount(); i++) {
    final ChartPanelView chartPanelView = gcDocument.getChartPanelView(i);
    final File file = new File(chartPanelView.getGCResource().getResourceName());
    saveDialog.setCurrentDirectory(file.getParentFile());
    saveDialog.setSelectedFile(file);
    final int val = saveDialog.showSaveDialog(gcViewer);
    if (val == JFileChooser.APPROVE_OPTION) {
      ExportExtensionFileFilter fileFilter = (ExportExtensionFileFilter) saveDialog.getFileFilter();
      // On OS/X if you don't select one of the filters and just press "Save" the filter may be null. Use the CSV one then
      if (fileFilter==null) {
        fileFilter = (ExportExtensionFileFilter) saveDialog.getChoosableFileFilters()[0];
      }
      exportFile(chartPanelView.getGCResource().getModel(),
          saveDialog.getSelectedFile(), 
          fileFilter.getExtension(),
          fileFilter.getDataWriterType());
    }
    else if (val == JFileChooser.ERROR_OPTION) {
      JOptionPane.showMessageDialog(gcViewer, LocalisationHelper.getString("fileexport_dialog_error_occured"), LocalisationHelper.getString("fileexport_dialog_write_file_failed"), JOptionPane.ERROR_MESSAGE);
    }
  }
}

代码示例来源:origin: marytts/marytts

private void jMenuItem_OpenActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jMenuItem_OpenActionPerformed
  // Allow user to choose a different voice (prompt set) without exiting the tool
  // Create a file chooser
  final JFileChooser openDialog = new JFileChooser();
  // Set the current directory to the voice currently in use
  openDialog.setCurrentDirectory(getVoiceFolderPath());
  openDialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  int result = openDialog.showDialog(AdminWindow.this, "Open Voice");
  if (result == JFileChooser.APPROVE_OPTION) {
    File voice = openDialog.getSelectedFile();
    setVoiceFolderPath(voice); // Set to the selected the voice folder path
    Test.output("Open voice: " + voice);
    setupVoice();
  } else {
    Test.output("Open command cancelled.");
  }
}// GEN-LAST:event_jMenuItem_OpenActionPerformed

代码示例来源:origin: skylot/jadx

public void openFile() {
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setAcceptAllFileFilterUsed(true);
  String[] exts = {"apk", "dex", "jar", "class", "zip", "aar", "arsc"};
  String description = "supported files: " + Arrays.toString(exts).replace('[', '(').replace(']', ')');
  fileChooser.setFileFilter(new FileNameExtensionFilter(description, exts));
  fileChooser.setToolTipText(NLS.str("file.open_action"));
  String currentDirectory = settings.getLastOpenFilePath();
  if (!currentDirectory.isEmpty()) {
    fileChooser.setCurrentDirectory(new File(currentDirectory));
  }
  int ret = fileChooser.showDialog(mainPanel, NLS.str("file.open_title"));
  if (ret == JFileChooser.APPROVE_OPTION) {
    settings.setLastOpenFilePath(fileChooser.getCurrentDirectory().getPath());
    openFile(fileChooser.getSelectedFile());
  }
}

代码示例来源:origin: stackoverflow.com

JFileChooser chooser;
if(pref.get("LAST_PATH", "") != null){
  // set last SELECTED file/directory path.
  chooser = new JFileChooser(pref.get("LAST_PATH", ""));
 } else{
   // set currentDirectory,  but dont select anything yet.
   chooser = new JFileChooser();
   chooser.setCurrentDirectory(new File(home_dir));
}

代码示例来源:origin: magefree/mage

protected void playerLoadDeck() {
  String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
  if (!lastFolder.isEmpty()) {
    fcSelectDeck.setCurrentDirectory(new File(lastFolder));
  }
  int ret = fcSelectDeck.showDialog(this, "Select Deck");
  if (ret == JFileChooser.APPROVE_OPTION) {
    File file = fcSelectDeck.getSelectedFile();
    this.txtPlayerDeck.setText(file.getPath());
    try {
      MageFrame.getPreferences().put("lastDeckFolder", file.getCanonicalPath());
    } catch (IOException ex) {
    }
  }
  fcSelectDeck.setSelectedFile(null);
}

代码示例来源:origin: deathmarine/Luyten

private void retrieveOpenDialogDir(JFileChooser fc) {
  try {
    String currentDirStr = luytenPrefs.getFileOpenCurrentDirectory();
    if (currentDirStr != null && currentDirStr.trim().length() > 0) {
      File currentDir = new File(currentDirStr);
      if (currentDir.exists() && currentDir.isDirectory()) {
        fc.setCurrentDirectory(currentDir);
      }
    }
  } catch (Exception e) {
    Luyten.showExceptionDialog("Exception!", e);
  }
}

代码示例来源:origin: org.brunocvcunha.inutils4j/inutils4j

public static File chooseDirOpen(File dir, String title) {
 JFileChooser chooser = new JFileChooser();
 chooser.setCurrentDirectory(dir);
 chooser.setDialogTitle(title);
 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
 chooser.setDialogType(JFileChooser.OPEN_DIALOG);
 chooser.showSaveDialog(null);
 File saveTo = chooser.getSelectedFile();
 return saveTo;
}

代码示例来源:origin: apache/axis2-java

private void browseWSDLFile(){
    fileChooser.setFileFilter(new WSDLFileFilter());
    fileChooser.setCurrentDirectory(archiveBean.getClassLoc());
    int returnVal = fileChooser.showOpenDialog(btnBrowse);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();
      txtWSDL.setText(file.getAbsolutePath());
    }
  }
}

代码示例来源:origin: plantuml/plantuml

private void displayDialogChangeDir() {
  final JFileChooser chooser = new JFileChooser();
  chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
  chooser.setDialogTitle("Directory to watch:");
  chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  chooser.setAcceptAllFileFilterUsed(false);
  final String currentPath = prefs.get(KEY_DIR, ".");
  chooser.setCurrentDirectory(new File(currentPath));
  Log.info("Showing OpenDialog");
  final int returnVal = chooser.showOpenDialog(this);
  Log.info("Closing OpenDialog");
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    final File dir = chooser.getSelectedFile();
    changeDir(dir);
  }
}

代码示例来源:origin: stackoverflow.com

JFileChooser chooser = new JFileChooser();

try {
  // Create a File object containing the canonical path of the
  // desired directory
  File f = new File(new File(".").getCanonicalPath());

  // Set the current directory
  chooser.setCurrentDirectory(f);
} catch (IOException e) {
}

代码示例来源:origin: magefree/mage

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
  String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
  if (!lastFolder.isEmpty()) {
    fcSelectDeck.setCurrentDirectory(new File(lastFolder));
    File file = fcSelectDeck.getSelectedFile();
          file = new File(lastFolder);

代码示例来源:origin: org.brunocvcunha.inutils4j/inutils4j

public static File chooseFileSave(File dir, String title) {
 JFileChooser chooser = new JFileChooser();
 chooser.setCurrentDirectory(dir);
 chooser.setDialogTitle(title);
 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
 chooser.setDialogType(JFileChooser.SAVE_DIALOG);
 chooser.showSaveDialog(null);
 File saveTo = chooser.getSelectedFile();
 return saveTo;
}

代码示例来源:origin: bcdev/beam

private File promptForRepositoryBaseDir() {
  final JFileChooser fileChooser = createDirectoryChooser();
  fileChooser.setCurrentDirectory(currentDirectory);
  final int response = fileChooser.showOpenDialog(mainPanel);
  currentDirectory = fileChooser.getCurrentDirectory();
  final File selectedDir = fileChooser.getSelectedFile();
  if (response == JFileChooser.APPROVE_OPTION) {
    return selectedDir;
  }
  return null;
}

代码示例来源:origin: dcevm/dcevm

public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Select a Java installation directory...");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setAcceptAllFileFilterUsed(false);
    Preferences p = Preferences.userNodeForPackage(Installer.class);
    final String prefID = "defaultDirectory";
    fc.setCurrentDirectory(new File(p.get(prefID, ".")));

    if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {

      Path dir = fc.getSelectedFile().toPath();
      p.put(prefID, dir.getParent().toString());
      try {
        installations.add(new Installation(config, dir));
      } catch (IOException ex) {
        MainWindow.showInstallerException(ex, parent);
      }
    }
  }
}

代码示例来源:origin: jpcsp/jpcsp

private JFileChooser makeJFileChooser() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(java.util.ResourceBundle.getBundle("jpcsp/languages/jpcsp").getString("MainGUI.strOpenELFPBP.text"));
    fc.setCurrentDirectory(new java.io.File("."));
    return fc;
  }
private void OpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenFileActionPerformed

代码示例来源:origin: org.brunocvcunha.inutils4j/inutils4j

public static File chooseFile(File dir, String title, int selectionMode) {
 JFileChooser chooser = new JFileChooser();
 chooser.setCurrentDirectory(dir);
 chooser.setDialogTitle(title);
 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
 chooser.setDialogType(JFileChooser.SAVE_DIALOG);
 chooser.showSaveDialog(null);
 File saveTo = chooser.getSelectedFile();
 return saveTo;
}

相关文章

JFileChooser类方法