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

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

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

JFileChooser.getSelectedFile介绍

暂无

代码示例

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

private void browseFiles() {
 jfc.setDialogTitle("Open file");
 int status = jfc.showOpenDialog(this);
 if (status == JFileChooser.APPROVE_OPTION) {
  urlTextField.setText(jfc.getSelectedFile().getPath());
  openButton.setEnabled(true);
 }
}

代码示例来源:origin: org.codehaus.groovy/groovy

public void actionPerformed(ActionEvent ae) {
    final JFileChooser jfc = new JFileChooser();
    final int response = jfc.showOpenDialog(LexerFrame.this);
    if (response != JFileChooser.APPROVE_OPTION) {
      return;
    }
    safeScanScript(jfc.getSelectedFile());
  }
};

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

private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed
  JFileChooser fc = new JFileChooser();
  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  int returnVal = fc.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    // System.out.println("Opening: " + file.getAbsolutePath());
    tfSoxPath.setText(file.getAbsolutePath());
  }
}// GEN-LAST:event_browseSoxActionPerformed

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

public File doSaveDialog(String recommendedFileName) {
  File selectedFile = null;
  initSaveDialog();
  retrieveSaveDialogDir(fcSave);
  fcSave.setSelectedFile(new File(recommendedFileName));
  int returnVal = fcSave.showSaveDialog(parent);
  saveSaveDialogDir(fcSave);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    selectedFile = fcSave.getSelectedFile();
  }
  return selectedFile;
}

代码示例来源: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: magefree/mage

private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportActionPerformed
  String lastFolder = MageFrame.getPreferences().get("lastImportFolder", "");
  if (!lastFolder.isEmpty()) {
    fcImportDeck.setCurrentDirectory(new File(lastFolder));
  int ret = fcImportDeck.showOpenDialog(this);
  if (ret == JFileChooser.APPROVE_OPTION) {
    File file = fcImportDeck.getSelectedFile();
    MageFrame.getDesktop().setCursor(new Cursor(Cursor.WAIT_CURSOR));
    try {

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

/**
 * Prompts the user for a file to load events from.
 * @param aIgnore an <code>ActionEvent</code> value
 */
public void actionPerformed(ActionEvent aIgnore) {
  LOG.info("load file called");
  if (mChooser.showOpenDialog(mParent) == JFileChooser.APPROVE_OPTION) {
    LOG.info("Need to load a file");
    final File chosen = mChooser.getSelectedFile();
    LOG.info("loading the contents of " + chosen.getAbsolutePath());
    try {
      final int num = loadFile(chosen.getAbsolutePath());
      JOptionPane.showMessageDialog(
        mParent,
        "Loaded " + num + " events.",
        "CHAINSAW",
        JOptionPane.INFORMATION_MESSAGE);
    } catch (Exception e) {
      LOG.warn("caught an exception loading the file", e);
      JOptionPane.showMessageDialog(
        mParent,
        "Error parsing file - " + e.getMessage(),
        "CHAINSAW",
        JOptionPane.ERROR_MESSAGE);
    }
  }
}

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

@Override
  public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser(rootDirectoryField.getText());
    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    fc.showDialog(frame, "Select");
    if (fc.getSelectedFile() != null) {
      rootDirectoryField.setText(fc.getSelectedFile().getAbsolutePath());
    }
  }
}

代码示例来源: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: EngineHub/WorldEdit

public static File showSaveDialog(String[] exts) {
  JFileChooser dialog = new JFileChooser();
  if (exts != null) {
    dialog.setFileFilter(new ExtensionFilter(exts));
  }
  int returnVal = dialog.showSaveDialog(null);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    return dialog.getSelectedFile();
  }
  return null;
}

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

/**
 * Opens a dialog and saves the output of the parser on the current
 * text.  If there is no current text, yell at the user and make
 * them feel bad instead.
 */
public void saveOutput() {
 if (textPane.getText().trim().length() == 0) {
  JOptionPane.showMessageDialog(this, "No text to parse ", null,
                 JOptionPane.ERROR_MESSAGE);
  return;
 }
 jfc.setDialogTitle("Save file");
 int status = jfc.showSaveDialog(this);
 if (status == JFileChooser.APPROVE_OPTION) {
  saveOutput(jfc.getSelectedFile().getPath());
 }
}

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

public File getFile(boolean open) {
 File file = null;
 int returnVal;
 if (open) {
  returnVal = fileChooser.showOpenDialog(frame);
 } else {
  returnVal = fileChooser.showSaveDialog(frame);
 }
 if(returnVal == JFileChooser.APPROVE_OPTION) {
  file = fileChooser.getSelectedFile();
  if (open && !checkFile(file)) { file = null; }
 }
 return file;
}

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

private void browseSoxActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_browseSoxActionPerformed
  JFileChooser fc = new JFileChooser();
  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  int returnVal = fc.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    // System.out.println("Opening: " + file.getAbsolutePath());
    tfSoxPath.setText(file.getAbsolutePath());
  }
}// GEN-LAST:event_browseSoxActionPerformed

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

public File doSaveAllDialog(String recommendedFileName) {
  File selectedFile = null;
  initSaveAllDialog();
  retrieveSaveDialogDir(fcSaveAll);
  fcSaveAll.setSelectedFile(new File(recommendedFileName));
  int returnVal = fcSaveAll.showSaveDialog(parent);
  saveSaveDialogDir(fcSaveAll);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    selectedFile = fcSaveAll.getSelectedFile();
  }
  return selectedFile;
}

代码示例来源: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: magefree/mage

fcSelectDeck.setCurrentDirectory(new File(lastFolder));
int ret = fcSelectDeck.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
  File file = fcSelectDeck.getSelectedFile();
        file = new File(lastFolder);

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

private void btnBrowseBackgroundImageActionPerformed(java.awt.event.ActionEvent evt) {
  int returnVal = fc_i.showOpenDialog(PreferencesDialog.this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc_i.getSelectedFile();
    txtBackgroundImagePath.setText(file.getAbsolutePath());
  }
}

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

/**
 * Uses a JFileChooser to select a file to opened with the
 * LF5 GUI.
 */
protected void requestOpen() {
 JFileChooser chooser;
 if (_fileLocation == null) {
  chooser = new JFileChooser();
 } else {
  chooser = new JFileChooser(_fileLocation);
 }
 int returnVal = chooser.showOpenDialog(_logMonitorFrame);
 if (returnVal == JFileChooser.APPROVE_OPTION) {
  File f = chooser.getSelectedFile();
  if (loadLogFile(f)) {
   _fileLocation = chooser.getSelectedFile();
   _mruFileManager.set(f);
   updateMRUList();
  }
 }
}

代码示例来源:origin: INRIA/spoon

@Override
  public void actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    boolean cont = chooser.showSaveDialog(SpoonModelTree.this) == JFileChooser.APPROVE_OPTION;
    if (cont) {
      SerializationModelStreamer ser = new SerializationModelStreamer();
      try {
        ser.save(factory, new FileOutputStream(chooser
            .getSelectedFile()));
      } catch (IOException e1) {
        Launcher.LOGGER.error(e1.getMessage(), e1);
      }
    }
  }
});

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/**
 * Show a save dialog with the file chooser set up according to the
 * parameters of this builder.
 * @return A file if the user clicks the accept button and a file or
 * folder was selected at the time the user clicked cancel.
 */
public File showSaveDialog() {
  JFileChooser chooser = createFileChooser();
  if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
    FileDialog fileDialog = createFileDialog( chooser.getCurrentDirectory() );
    if( null != fileDialog ) {
      return showFileDialog( fileDialog, FileDialog.SAVE );
    }
  }
  int result = chooser.showSaveDialog(findDialogParent());
  if (JFileChooser.APPROVE_OPTION == result) {
    return chooser.getSelectedFile();
  } else {
    return null;
  }
}

相关文章

JFileChooser类方法