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

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

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

JFileChooser.addChoosableFileFilter介绍

暂无

代码示例

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

private JFileChooser createFileChooser(String... fileFilters) {
  JFileChooser fc = new JFileChooser();
  for (String fileFilter : fileFilters) {
    fc.addChoosableFileFilter(new FileChooserFileFilter(fileFilter));
  }
  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fc.setMultiSelectionEnabled(false);
  return fc;
}

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

protected String playerLoadDeck() {
  if (fcSelectDeck == null) {
    fcSelectDeck = new JFileChooser();
    fcSelectDeck.setAcceptAllFileFilterUsed(false);
    fcSelectDeck.addChoosableFileFilter(new DeckFilter());
  }
  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();
    return (file.getPath());
  }
  return "";
}

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

`JFileChooser dialog = new JFileChooser();
dialog.setMultiSelectionEnabled(true);
dialog.showOpenDialog(null);
dialog.addChoosableFileFilter(new FileNameExtensionFilter("pngFilter", "png"));
dialog.addChoosableFileFilter(new FileNameExtensionFilter("jpgFilter", "jpg"));
File[] file = dialog.getSelectedFiles();`

代码示例来源:origin: unchartedsoftware/aperture-tiles

@Override
  public void actionPerformed (ActionEvent event) {
    _fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    _fileChooser.setFileFilter(new FileNameExtensionFilter("zip files", "zip"));
    _fileChooser.addChoosableFileFilter(_fileChooser.getAcceptAllFileFilter());
    int returnVal = _fileChooser.showOpenDialog(ZipFilePyramidIOSelector.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = _fileChooser.getSelectedFile();
      _zipPathField.setText(file.getAbsolutePath());
    }
  }
});

代码示例来源:origin: locationtech/jts

void menuLoadXmlTestFile_actionPerformed(ActionEvent e) {
 try {
  fileChooser.removeChoosableFileFilter(SwingUtil.JAVA_FILE_FILTER);
  fileChooser.addChoosableFileFilter(SwingUtil.XML_FILE_FILTER);
  fileChooser.setDialogTitle("Open XML Test File(s)");
  fileChooser.setMultiSelectionEnabled(true);
  if (JFileChooser.APPROVE_OPTION == fileChooser.showOpenDialog(this)) {
   File[] files = fileChooser.getSelectedFiles();
   if (files.length == 0) {
    files = new File[]{fileChooser.getSelectedFile()};
   }
   openXmlFilesAndDirectories(files);
  }
 }
 catch (Exception x) {
  SwingUtil.reportException(this, x);
 }
}

代码示例来源:origin: knowm/XChart

JFileChooser fileChooser = new JFileChooser();
FileFilter pngFileFilter = new SuffixSaveFilter("png"); // default
fileChooser.addChoosableFileFilter(pngFileFilter);
fileChooser.addChoosableFileFilter(new SuffixSaveFilter("jpg"));
fileChooser.addChoosableFileFilter(new SuffixSaveFilter("bmp"));
fileChooser.addChoosableFileFilter(new SuffixSaveFilter("gif"));
 Class.forName("de.erichseifert.vectorgraphics2d.VectorGraphics2D");
 fileChooser.addChoosableFileFilter(new SuffixSaveFilter("svg"));
 fileChooser.addChoosableFileFilter(new SuffixSaveFilter("eps"));
 fileChooser.addChoosableFileFilter(new SuffixSaveFilter("pdf"));
} catch (ClassNotFoundException e) {
 if (fileChooser.getSelectedFile() != null) {
  File theFileToSave = fileChooser.getSelectedFile();
  try {
   if (fileChooser.getFileFilter() == null) {

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

public Export(final GCViewerGui gcViewer) {
  this.gcViewer = gcViewer;
  putValue(NAME, LocalisationHelper.getString("main_frame_menuitem_export"));
  putValue(MNEMONIC_KEY, new Integer(LocalisationHelper.getString("main_frame_menuitem_mnemonic_export").charAt(0)));
  putValue(SHORT_DESCRIPTION, LocalisationHelper.getString("main_frame_menuitem_hint_export"));
  putValue(ACTION_COMMAND_KEY, ActionCommands.EXPORT.toString());
  putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() ));
  putValue(SMALL_ICON, ImageHelper.loadImageIcon("save.png"));
  setEnabled(false);
  saveDialog = new JFileChooser();
  saveDialog.setDialogTitle(LocalisationHelper.getString("fileexport_dialog_title"));
  saveDialog.removeChoosableFileFilter(saveDialog.getAcceptAllFileFilter());
  for (ExportExtensionFileFilter filter : ExportExtensionFileFilter.EXT_FILE_FILTERS) {
    saveDialog.addChoosableFileFilter(filter);
  }
}

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

//config fileChooser
  JFileChooser fc = new JFileChooser(lastOpenDir);

  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fc.setDialogTitle("Load Beacon List");
  fc.removeChoosableFileFilter(fc.getFileFilter());  //remove the default file filter
  FileFilter filter = new FileNameExtensionFilter("EXE file", "exe");
  fc.addChoosableFileFilter(filter); //add XML file filter

  //show dialog
  int returnVal = fc.showOpenDialog(this);
  if(returnVal == JFileChooser.APPROVE_OPTION){

    File selectedDir = fc.getSelectedFile();
...

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

File fileChoosen = null;
while (true) {
 fchooser = new JFileChooser();
 if (SX.isMac()) {
  fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always");
  for (Object filter : filters) {
   if (filter instanceof SikulixFileFilter) {
    fchooser.addChoosableFileFilter((SikulixFileFilter) filter);
   } else {
    fchooser.setFileFilter((FileNameExtensionFilter) filter);
  return null;
 fileChoosen = fchooser.getSelectedFile();
 if (mode == FileDialog.LOAD) {
  if (checkSikuli && !isValidScript(fileChoosen)) {

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

JFileChooser FC=new JFileChooser("C:/");
FC.addChoosableFileFilter(new jpgSaveFilter());
FC.addChoosableFileFilter(new jpegSaveFilter());
FC.addChoosableFileFilter(new PngSaveFilter());
FC.addChoosableFileFilter(new gifSaveFilter());
FC.addChoosableFileFilter(new BMPSaveFilter());
FC.addChoosableFileFilter(new wbmpSaveFilter());

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

/**
   * Applies the configuration to {@code fileChooser}.
   * 
   * @param fileChooser a {@code JFileChoose} to configure.
   */
  public void configure(JFileChooser fileChooser) {
    final File selectedFile = fileChooser.getSelectedFile();
    fileChooser.setSelectedFile(null);

    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.setFileSelectionMode(this.selectionMode);

    fileChooser.resetChoosableFileFilters();
    for (FileFilter filter : this.filters) {
      fileChooser.addChoosableFileFilter(filter);
    }
    fileChooser.setAcceptAllFileFilterUsed(this.allowAll);

    fileChooser.setSelectedFile(selectedFile);
  }
}

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

private File browseForFile(String currentPath, SimpleFileFilter filter) {
 JFileChooser fc = new JFileChooser(currentPath);
 fc.addChoosableFileFilter(filter);
 fc.setFileFilter(filter);
 int returnVal = fc.showOpenDialog(this);
 if (returnVal == JFileChooser.APPROVE_OPTION)
  return fc.getSelectedFile();
  
 return null;
}

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

public static JFileChooser getSettingsFileChooser() {
  FirmwareSettingsFileTypeFilter filter = new FirmwareSettingsFileTypeFilter();
  
  // Setup file browser with the last path used.
  JFileChooser fileChooser = new JFileChooser();
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setFileHidingEnabled(true);
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setAcceptAllFileFilterUsed(true);
  fileChooser.setFileFilter(filter);
  
  return fileChooser;
}

代码示例来源:origin: locationtech/jts

void menuSaveAsJava_actionPerformed(ActionEvent e) {
 try {
  fileChooser.removeChoosableFileFilter(SwingUtil.XML_FILE_FILTER);
  fileChooser.addChoosableFileFilter(SwingUtil.JAVA_FILE_FILTER);
  fileChooser.setDialogTitle("Save Java File");
  if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) {
   File file = fileChooser.getSelectedFile();
   if (! SwingUtil.confirmOverwrite(this, file)) return;
   String className = fileChooser.getSelectedFile().getName();
   int extensionIndex = className.lastIndexOf(".");
   if (extensionIndex > 0) {
    className = className.substring(0, extensionIndex);
   }
   ;
   FileUtil.setContents(fileChooser.getSelectedFile().getPath(), JavaTestWriter.getRunJava(className, tbModel));
  }
 }
 catch (Exception x) {
  SwingUtil.reportException(this, x);
 }
}

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

private void btnFilenameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilenameActionPerformed
  JFileChooser fc = new JFileChooser();
  fc.setDialogTitle(java.util.ResourceBundle.getBundle("jpcsp/languages/jpcsp").getString("DumpCodeDialog.dlgOutputFile.title"));
  fc.setSelectedFile(new File(txtFilename.getText()));
  fc.addChoosableFileFilter(Constants.fltTextFiles);
  fc.setFileFilter(Constants.fltTextFiles);
  int returnVal = fc.showOpenDialog(this);
  if (returnVal != JFileChooser.APPROVE_OPTION) {
    return;
  }
  txtFilename.setText(fc.getSelectedFile().getAbsolutePath());
}//GEN-LAST:event_btnFilenameActionPerformed

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

public static JFileChooser getGcodeFileChooser(String startDir) {
  //Setup the file filter for gcode files.
  GcodeFileTypeFilter filter = new GcodeFileTypeFilter();
  
  // Setup file browser with the last path used.
  JFileChooser fileChooser = new JFileChooser(startDir); 
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setFileHidingEnabled(true);
  fileChooser.addChoosableFileFilter(filter);
  fileChooser.setAcceptAllFileFilterUsed(true);
  fileChooser.setFileFilter(filter);
  
  return fileChooser;
}

代码示例来源:origin: igniterealtime/Spark

private void addCertificate() {
  fileChooser.setAcceptAllFileFilterUsed(false);
  fileChooser.addChoosableFileFilter(certFilter);
  fileChooser.setFileFilter(certFilter);
  int retVal = fileChooser.showOpenDialog(this);
  if (retVal == JFileChooser.APPROVE_OPTION) {
    File file = fileChooser.getSelectedFile();
    try {
      certControll.addEntryFileToKeyStore(file);
    } catch (CertificateException e) {
      JOptionPane.showMessageDialog(null, Res.getString("dialog.cannot.upload.certificate.might.be.ill.formated"));
      Log.error("Cannot upload certificate file", e);
    } catch (KeyStoreException | InvalidNameException | IOException e) {
      JOptionPane.showMessageDialog(null, "dialog.cannot.upload.certificate");
      Log.error("Cannot upload certificate file", e);
    }
  }
}

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

private void fileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileButtonActionPerformed
    JFileChooser fc = new JFileChooser();

    fc.setCurrentDirectory(new java.io.File("."));
    fc.setSelectedFile(new File(xmlpath.getText()));

    fc.addChoosableFileFilter(Constants.fltXMLFiles);
    fc.setFileFilter(Constants.fltXMLFiles);

    int result = fc.showOpenDialog(this);
    if (result == JFileChooser.APPROVE_OPTION) {
      xmlpath.setText(fc.getSelectedFile().getPath());
      setLogSettingsFile();
    }
}//GEN-LAST:event_fileButtonActionPerformed

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

/**
 * Creates new form NewPlayerPanel
 */
public NewPlayerPanel() {
  initComponents();
  fcSelectDeck = new JFileChooser();
  fcSelectDeck.setAcceptAllFileFilterUsed(false);
  fcSelectDeck.addChoosableFileFilter(new DeckFilter());
  String deckPath = MageFrame.getPreferences().get("defaultDeckPath", "");
  if (deckPath.isEmpty()) {
    if (Config.defaultDeckPath != null) {
      deckPath = Config.defaultDeckPath;
    }
  }
  this.txtPlayerDeck.setText(deckPath);
  if (Config.defaultComputerName != null) {
    this.txtPlayerName.setText(Config.defaultComputerName);
  }
}

代码示例来源:origin: locationtech/jts

void menuSaveAsXml_actionPerformed(ActionEvent e) {
 try {
  fileChooser.removeChoosableFileFilter(SwingUtil.JAVA_FILE_FILTER);
  fileChooser.addChoosableFileFilter(SwingUtil.XML_FILE_FILTER);
  fileChooser.setDialogTitle("Save XML Test File");
  if (JFileChooser.APPROVE_OPTION == fileChooser.showSaveDialog(this)) {
   File file = fileChooser.getSelectedFile();
   if (! SwingUtil.confirmOverwrite(this, file)) return;
   FileUtil.setContents(fileChooser.getSelectedFile().getPath(), 
       XMLTestWriter.getRunXml(tbModel.getTestCaseList(), tbModel.getPrecisionModel()) );
  }
 }
 catch (Exception x) {
  SwingUtil.reportException(this, x);
 }
}

相关文章

JFileChooser类方法