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

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

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

JFileChooser.removeChoosableFileFilter介绍

暂无

代码示例

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

private static void setupFilterToOnlyOneFormat(JFileChooser chooser,
                        FileFilter chosenFilter) {
  for (FileFilter filter : OPEN_SAVE_FILTERS) {
    if(filter != chosenFilter) {
      chooser.removeChoosableFileFilter(filter);
    }
  }
  chooser.setFileFilter(chosenFilter);
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core

private static void clearFileFilters() {
  FileFilter[] filters = jfc.getChoosableFileFilters();
  for (FileFilter filter : filters) {
    jfc.removeChoosableFileFilter(filter);
  }
}

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

private static void limpaChooser(JFileChooser chooser) {
  chooser.setCurrentDirectory(new File("."));
  chooser.setSelectedFile(null);
  chooser.setFileFilter(null);
  chooser.setAcceptAllFileFilterUsed(true);
  chooser.setMultiSelectionEnabled(false);
  FileFilter filtros[] = chooser.getChoosableFileFilters();
  for (FileFilter filtro : filtros) {
    chooser.removeChoosableFileFilter(filtro);
  }
}

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

JFileChooser fileChooser = new JFileChooser();
// select only zip files and add "Zip Files" option
fileChooser.setFileFilter(new FileNameExtensionFilter("Zip Files", "zip"));
// remove "All Files" option
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());

代码示例来源:origin: girtel/Net2Plan

private void checkFileChooser(File currentFolder) {
  if (fileChooser == null) {
    fileChooser = currentFolder == null ? new JFileChooser() : new JFileChooser(currentFolder);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    for (FileFilter aux : fileChooser.getChoosableFileFilters()) fileChooser.removeChoosableFileFilter(aux);
    fileChooser.addChoosableFileFilter(ClassLoaderUtils.getFileFilter());
    fileChooser.setAcceptAllFileFilterUsed(false);
  }
}

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

JFileChooser fc = new JFileChooser(){
   @Override
   public void approveSelection(){
     File f = getSelectedFile();
     if(!f.exists() ){                   
       JOptionPane.showMessageDialog(null, "Error");                   
     }
   }           
 };
 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
 fc.setDialogTitle("Open test");
 fc.removeChoosableFileFilter(fc.getFileFilter());  //remove the default file filter
 FileFilter filter = new FileNameExtensionFilter("XML file", "xml");
 fc.addChoosableFileFilter(filter); //add XML file filter
 //show dialog
 int returnVal = fc.showOpenDialog(appFrame); 
 if(returnVal == JFileChooser.APPROVE_OPTION){/* ...  */}

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

JFileChooser jfc=new JFileChooser(System.getProperty("user.dir","."));

FileFilter ff = new FileFilter(){
  public boolean accept(File f){
    if(f.isDirectory()) return true;
    else if(f.getName().endsWith(".mp3")) return true;
      else return false;
  }
  public String getDescription(){
    return "MP3 files";
  }
};

jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
jfc.setFileFilter(ff);

if(jfc.showDialog(frame,"openG")==JFileChooser.APPROVE_OPTION){
    String fileName = jfc.getSelectedFile().getPath();
}

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

private void openDME() {
  JFileChooser fc = new JFileChooser();
  if (fc.getChoosableFileFilters().length > 0)
    fc.removeChoosableFileFilter(fc.getChoosableFileFilters()[0]);
  fc.addChoosableFileFilter(new FileNameExtensionFilter("BYOND Environments (*.dme)", "dme"));
  int returnVal = fc.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    openDME(fc.getSelectedFile());
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial

private void onExportFilenameBrowseClick() {
  File oldFile = getExecutableFile();
  JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(MercurialOptionsPanelController.class, "ACSD_ExportBrowseFolder"), oldFile);   // NOI18N
  fileChooser.setDialogTitle(NbBundle.getMessage(MercurialOptionsPanelController.class, "ExportBrowse_title"));                                            // NOI18N
  fileChooser.setMultiSelectionEnabled(false);
  FileFilter[] old = fileChooser.getChoosableFileFilters();
  for (int i = 0; i < old.length; i++) {
    FileFilter fileFilter = old[i];
    fileChooser.removeChoosableFileFilter(fileFilter);
  }
  fileChooser.showDialog(panel, NbBundle.getMessage(MercurialOptionsPanelController.class, "OK_Button"));                                            // NOI18N
  File f = fileChooser.getSelectedFile();
  if (f != null) {
    panel.exportFilenameTextField.setText(f.getAbsolutePath());
  }
}

代码示例来源: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: org.netbeans.modules/org-netbeans-modules-mercurial

private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
  File oldFile = new File(tfRootPath.getText());
  JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(CreatePanel.class, "ACSD_BrowseFolder"), oldFile); //NOI18N
  fileChooser.setDialogTitle(NbBundle.getMessage(CreatePanel.class, "Browse_title")); //NOI18N
  fileChooser.setMultiSelectionEnabled(false);
  FileFilter[] old = fileChooser.getChoosableFileFilters();
  for (int i = 0; i < old.length; i++) {
    FileFilter fileFilter = old[i];
    fileChooser.removeChoosableFileFilter(fileFilter);
  }
  fileChooser.addChoosableFileFilter(new FileFilter() {
    public boolean accept(File f) {
      return f.isDirectory();
    }
    public String getDescription() {
      return NbBundle.getMessage(CreatePanel.class, "Folders"); //NOI18N
    }
  });
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fileChooser.showDialog(this, NbBundle.getMessage(CreatePanel.class, "OK_Button")); //NOI18N
  File f = fileChooser.getSelectedFile();
  if (f != null) {
    tfRootPath.setText(f.getAbsolutePath());
  }
}//GEN-LAST:event_btnBrowseActionPerformed

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

void actionLoadXmlTestFolder() {
 try {
  directoryChooser.removeChoosableFileFilter(SwingUtil.JAVA_FILE_FILTER);
  directoryChooser.setDialogTitle("Open Folder(s) Containing XML Test Files");
  directoryChooser.setMultiSelectionEnabled(true);
  if (JFileChooser.APPROVE_OPTION == directoryChooser.showOpenDialog(this)) {
   File[] files = directoryChooser.getSelectedFiles();
   if (files.length == 0) {
    files = new File[]{fileChooser.getSelectedFile()};
   }
   openXmlFilesAndDirectories(files);
  }
 }
 catch (Exception x) {
  reportException(x);
 }
}

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

public static void addExtension(JFileChooser fileChooser, String extension,
    String description) {
  FileFilter existing = null;
  for (FileFilter ff : fileChooser.getChoosableFileFilters()) {
    if (ff instanceof FF) {
      if (((FF) ff).getExtension().equals(extension.toUpperCase())) {
        existing = ff;
        break;
      }
    }
  }
  if (existing != null) {
    fileChooser.removeChoosableFileFilter(existing);
  }
  fileChooser.addChoosableFileFilter(new FF(extension, description));
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial

private void onBrowseClick() {
  File oldFile = defaultWorkingDirectory();
  JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "ACSD_BrowseFolder"), oldFile);   // NO I18N
  fileChooser.setDialogTitle(NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "Browse_title"));                                            // NO I18N
  fileChooser.setMultiSelectionEnabled(false);
  FileFilter[] old = fileChooser.getChoosableFileFilters();
  for (int i = 0; i < old.length; i++) {
    FileFilter fileFilter = old[i];
    fileChooser.removeChoosableFileFilter(fileFilter);
  }
  fileChooser.addChoosableFileFilter(new FileFilter() {
    public boolean accept(File f) {
      return f.isDirectory();
    }
    public String getDescription() {
      return NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "Folders"); // NOI18N
    }
  });
  fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  fileChooser.showDialog(this, NbBundle.getMessage(CloneDestinationDirectoryPanel.class, "OK_Button"));                                            // NO I18N
  File f = fileChooser.getSelectedFile();
  if (f != null) {
    directoryField.setText(f.getAbsolutePath());
  }
}

代码示例来源:origin: com.mgmtp.gcviewer/gcviewer

public Export(final GCViewerGui gcViewer) {
  this.gcViewer = gcViewer;
  putValue(NAME, GCViewerGui.localStrings.getString("main_frame_menuitem_export"));
  putValue(MNEMONIC_KEY, new Integer(GCViewerGui.localStrings.getString("main_frame_menuitem_mnemonic_export").charAt(0)));
  putValue(SHORT_DESCRIPTION, GCViewerGui.localStrings.getString("main_frame_menuitem_hint_export"));
  putValue(ACTION_COMMAND_KEY, "export");
  putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() ));
  putValue(SMALL_ICON, new ImageIcon(Toolkit.getDefaultToolkit().getImage(gcViewer.getClass().getResource("images/save.png"))));
  setEnabled(false);
  
  saveDialog = new JFileChooser();
  saveDialog.setDialogTitle(GCViewerGui.localStrings.getString("fileexport_dialog_title"));
  saveDialog.removeChoosableFileFilter(saveDialog.getAcceptAllFileFilter());
  saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".csv", GCViewerGui.localStrings.getString("fileexport_dialog_csv"), DataWriterType.CSV));
  saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".txt", GCViewerGui.localStrings.getString("fileexport_dialog_txt"), DataWriterType.PLAIN));
  saveDialog.addChoosableFileFilter(new ExtensionFileFilter(".simple.log", GCViewerGui.localStrings.getString("fileexport_dialog_simplelog"), DataWriterType.SIMPLE));
}

代码示例来源: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);
 }
}

代码示例来源:origin: girtel/Net2Plan

@Override
  public void actionPerformed(ActionEvent ae) {
    try {
      JFileChooser fc = new FileChooserConfirmOverwrite();
      for (FileFilter existingFilter : fc.getChoosableFileFilters())
        fc.removeChoosableFileFilter(existingFilter);
      fc.setFileFilter(new FileNameExtensionFilter("HTML files", "html"));
      fc.setAcceptAllFileFilterUsed(false);
      fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
      int rc = fc.showSaveDialog(null);
      if (rc != JFileChooser.APPROVE_OPTION) return;
      File htmlName = fc.getSelectedFile();
      saveToFile(htmlName);
      ErrorHandling.showInformationDialog("Report saved successfully", "Save report to file");
    } catch (Throwable ex) {
      ErrorHandling.addErrorOrException(ex, ReportBrowser.class);
      ErrorHandling.showErrorDialog("Please, check console for more information", "Error exporting report");
    }
  }
});

相关文章

JFileChooser类方法