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

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

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

JFileChooser.setSelectedFile介绍

暂无

代码示例

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

JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setSelectedFile(new File("fileToSave.txt"));
jFileChooser.showSaveDialog(parent);

代码示例来源:origin: bonnyfone/vectalign

private File showOpenDir(String title, File lastFile){
  final JFileChooser fc = new JFileChooser();
  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fc.setDialogTitle(title);
  if(lastFile != null)
    fc.setSelectedFile(lastFile);
  fc.setFileFilter(new FileFilter() {
    @Override
    public boolean accept(File f) {
      if (f.isDirectory())
        return true;
      return false;
    }
    @Override
    public String getDescription() {
      return "Directory";
    }
  });
  int returnVal = fc.showOpenDialog(null);
  File file = null;
  if(returnVal == JFileChooser.APPROVE_OPTION)
    file = fc.getSelectedFile();
  return file;
}

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

private void doExportTree() {
 JFileChooser chooser = new JFileChooser();
 chooser.setSelectedFile(new File("./tree.png"));
 FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG images", "png");
 chooser.setFileFilter(filter);
 int status = chooser.showSaveDialog(this);
 if (status != JFileChooser.APPROVE_OPTION)
  return;
 Dimension size = tjp.getPreferredSize();
 BufferedImage im = new BufferedImage((int) size.getWidth(),
                    (int) size.getHeight(),
                    BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = im.createGraphics();
 tjp.paint(g);
 try {
  ImageIO.write(im, "png", chooser.getSelectedFile());
 } catch (IOException e) {
  JOptionPane.showMessageDialog(this, "Failed to save the tree image file.\n"
                 + e.getLocalizedMessage(), "Export Error",
                 JOptionPane.ERROR_MESSAGE);
 }
}

代码示例来源: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: winder/Universal-G-Code-Sender

public void loadSettings() {
  portCombo.setSelectedItem(backend.getSettings().getPort());
  baudCombo.setSelectedItem(backend.getSettings().getPortRate());
  firmwareCombo.setSelectedItem(backend.getSettings().getFirmwareVersion());
  String lastOpenedFilename = backend.getSettings().getLastOpenedFilename();
  if (lastOpenedFilename != null && !lastOpenedFilename.isEmpty()) {
    fileChooser.setSelectedFile(new File(lastOpenedFilename));
  }
  updateCurrentFileLabel(backend.getGcodeFile());
  jogPanel.loadSettings();
}

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

JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(dirOfYourChoice);
fc.setSelectedFile(fileOfYourChoice); 
fc.setFileFilter(filterOfYourChoice);
int okCancel = fc.showSaveDialog(null);

代码示例来源:origin: johnjohndoe/ProGuard

public void actionPerformed(ActionEvent e)
  {
    fileChooser.setDialogTitle(msg("selectStackTraceFile"));
    fileChooser.setSelectedFile(null);
    int returnValue = fileChooser.showOpenDialog(ProGuardGUI.this);
    if (returnValue == JFileChooser.APPROVE_OPTION)
    {
      loadStackTrace(fileChooser.getSelectedFile());
    }
  }
}

代码示例来源:origin: winder/Universal-G-Code-Sender

private void exportButtonActionPerformed() {
  JFileChooser fileChooser = new JFileChooser();
  String date = LocalDate.now().format(DateTimeFormatter.ISO_DATE);
  fileChooser.setSelectedFile(new File("firmware_" + date + ".settings"));
  fileChooser.setFileFilter(new FirmwareSettingsFileTypeFilter());
  if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
    File file = fileChooser.getSelectedFile();
    FirmwareSettingUtils.exportSettings(file, backend.getController());
  }
}

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

private void initFileChoosers() {
 if (pngFileChooser == null) {
  pngFileChooser = new JFileChooser();
  pngFileChooser.addChoosableFileFilter(SwingUtil.PNG_FILE_FILTER);
  pngFileChooser.setDialogTitle("Save PNG");
  pngFileChooser.setSelectedFile(new File("geoms.png"));
 }
}

代码示例来源:origin: net.java.openjdk.cacio/cacio-shared

public void setFile(String file) {
  fileChooser.setSelectedFile(new File(file));
}

代码示例来源:origin: bonnyfone/vectalign

private File showOpenFile(String title, File lastFile){
  final JFileChooser fc = new JFileChooser();
  fc.setDialogTitle(title);
  if(lastFile != null)
    fc.setSelectedFile(lastFile);
  fc.setFileFilter(new FileFilter() {
    @Override
    public boolean accept(File f) {
      if (f.isDirectory())
        return true;
      String extension = Utils.getExtension(f);
      if (extension != null) {
        if (extension.equals("svg"))
          return true;
        else
          return false;
      }
      return false;
    }
    @Override
    public String getDescription() {
      return "SVG images";
    }
  });
  int returnVal = fc.showOpenDialog(null);
  File file = null;
  if(returnVal == JFileChooser.APPROVE_OPTION)
    file = fc.getSelectedFile();
  return file;
}

代码示例来源:origin: ribomation/DroidAtScreen1

private JFileChooser createChooser(File dir, File file, String[] exts) {
  JFileChooser chooser = new JFileChooser();
  chooser.setCurrentDirectory(dir);
  chooser.setSelectedFile(file);
  chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  chooser.addChoosableFileFilter(new FileNameExtensionFilter("Image Files", exts));
  return chooser;
}

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

JScrollPane logScrollPane = new JScrollPane(content);
jfc = new JFileChooser();
jfc.setCurrentDirectory(new File(default_directory));
jfc.setSelectedFile(new File(default_filename));
jfc.addPropertyChangeListener(new PropertyChangeListener() {
      jfc.setCurrentDirectory(new File("/home/foo"));
      jfc.setSelectedFile(new File("default" + version + ".txt"));
if (returnVal == JFileChooser.APPROVE_OPTION)
  File file = jfc.getSelectedFile();

代码示例来源: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: stackoverflow.com

JFileChooser fileChooser = new JFileChooser();
fileChooser.setSelectedFile(new File("C:\\file.txt"));
fileChooser.showSaveDialog(null);

代码示例来源:origin: sing-group/GC4S

/**
 * Clears the selected file.
 */
public void clearSelectedFile() {
  if (this.selectedFile != null) {
    this.selectedFile = null;
    fileName.setText("");
    fileName.setToolTipText("");
    filechooser.setSelectedFile(new File(""));
  }
}

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

protected void browse() {
  JFileChooser dialog;
  Object format = this.parameter.metadata.get(Parameter.EXT);
  if (format instanceof FileDataStoreFactorySpi) {
    dialog = new JFileDataStoreChooser((FileDataStoreFactorySpi) format);
  } else if (format instanceof String) {
    dialog = new JFileDataStoreChooser((String) format);
  } else if (format instanceof String[]) {
    dialog = new JFileDataStoreChooser((String[]) format);
  } else {
    dialog = new JFileChooser();
  }
  dialog.setSelectedFile(getFile());
  int returnVal = dialog.showOpenDialog(browse);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = dialog.getSelectedFile();
    setValue(file);
  }
}

代码示例来源:origin: org.gdl-lang.gdl-tools/openehr-utils-gui-swing

private static JFileChooser getArchetypeFileChooser(File selectedFile) {
  JFileChooser fileChooser = new JFileChooser();
  FileNameExtensionFilter filter = new FileNameExtensionFilter(
      OpenEHRLanguageManager.getMessage("Archetype"), "adl");
  fileChooser.setDialogTitle(OpenEHRLanguageManager.getMessage("ImportArchetype"));
  fileChooser.setFileFilter(filter);
  if (selectedFile != null) {
    fileChooser.setSelectedFile(selectedFile);
  }
  return fileChooser;
}

代码示例来源:origin: RaiMan/SikuliX2

File fileChoosen = null;
while (true) {
 fchooser = new JFileChooser();
 if (SX.isMac()) {
  fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always");
  fchooser.setCurrentDirectory(new File(last_dir));
 fchooser.setSelectedFile(null);
 if (SX.isMac() && type == DIRS) {
  fchooser.setFileSelectionMode(DIRSANDFILES);
  return null;
 fileChoosen = fchooser.getSelectedFile();
 if (mode == FileDialog.LOAD) {
  if (checkSikuli && !isValidScript(fileChoosen)) {
File selected = new File(fileChoosen.getAbsolutePath());
if (!selected.isDirectory() || type == DIRS) {
 selected = selected.getParentFile();

相关文章

JFileChooser类方法