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

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

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

JFileChooser.setFileFilter介绍

暂无

代码示例

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

JFileChooser jf = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
jf.setFileFilter(filter);

代码示例来源:origin: EngineHub/WorldEdit

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

代码示例来源: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: pvto/konte-art

public void setFileChooser()
{
  if (fc == null)
  {
    File file = new File(getPath().replaceFirst("/$", ""));
    if (file == null)
      file = new File(".");
    fc = new JFileChooser(file);
    fc.setFileFilter(fname);
    
  }        
}    
public JFileChooser getFc() { return fc; }

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

private JFileChooser getJFileChooser(File filename) {
  File folder = null;
  if (filename != null)
    folder = filename.getParentFile();
  if (folder == null && baseFilename != null)
    folder = baseFilename.getParentFile();
  if (folder == null) {
    String folderStr = PREFS.get(PREF_FOLDER, null);
    if (folderStr != null)
      folder = new File(folderStr);
  }
  JFileChooser fileChooser = new MyFileChooser(folder);
  fileChooser.setFileFilter(new FileNameExtensionFilter("FSM", "fsm"));
  return fileChooser;
}

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

import java.io.File;
import javax.swing.JFileChooser;

public class ShowDirectoriesOnly {
  public static void main(String[] args) {
   JFileChooser fileChooser = new JFileChooser( "." );
   fileChooser.setControlButtonsAreShown( false );
   fileChooser.setFileFilter( new FolderFilter() );
   fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
   fileChooser.showOpenDialog(null);
  }

  private static class FolderFilter extends javax.swing.filechooser.FileFilter {
   @Override
   public boolean accept( File file ) {
    return file.isDirectory();
   }

   @Override
   public String getDescription() {
    return "We only take directories";
   }
  }
}

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

// create a filechooser;
JFileChooser chooser = new JFileChooser(cwd);
FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter(
   "xml files (*.xml)", "xml");

chooser.setDialogTitle("Open schedule file");
// set selected filter
chooser.setFileFilter(xmlfilter);

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

public LoadForm(NavigateAction forwardAction, NavigateAction backwardAction) {
  super(forwardAction, backwardAction);
  fileChooser = new JFileChooser(new File(System.getProperty("user.dir")));
  fileChooser.setFileFilter(new BuildPropFilter());
  properties = new Properties();
  add(fileChooser);
}

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

private JFileChooser criarSeletorArquivo() {
  JFileChooser dialogoSelecaoArquivo = FabricaDeFileChooser.getFileChooserAbertura();
  dialogoSelecaoArquivo.setCurrentDirectory(new File(Configuracoes.getInstancia().getCaminhoUltimoDiretorio()));
  dialogoSelecaoArquivo.setMultiSelectionEnabled(true);
  dialogoSelecaoArquivo.setAcceptAllFileFilterUsed(false);
  dialogoSelecaoArquivo.addChoosableFileFilter(filtroExercicio);
  dialogoSelecaoArquivo.addChoosableFileFilter(filtroPrograma);
  dialogoSelecaoArquivo.addChoosableFileFilter(filtroTodosSuportados);
  dialogoSelecaoArquivo.setFileFilter(filtroPrograma);
  return dialogoSelecaoArquivo;
}

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

/**
   * Displays a file chooser dialog and returns the selected file.
   *
   * @return the selected file
   */
  static File getFile() {
    JFileChooser chooser = new JFileChooser(cwd);
    chooser.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(File f) {
            return true;
          }
          @Override
          public String getDescription() {
            return "All files";
          }
        });
    if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
      return null;
    }
    cwd = chooser.getCurrentDirectory();
    return chooser.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: 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: 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: nz.ac.waikato.cms.weka/weka-stable

protected void setupFileChooser() {
 if (m_fileChooser == null) {
  m_fileChooser =
   new JFileChooser(new File(System.getProperty("user.dir")));
 }
 m_fileChooser.addChoosableFileFilter(m_binaryFilter);
 if (KOML.isPresent()) {
  m_fileChooser.addChoosableFileFilter(m_KOMLFilter);
 }
 if (XStream.isPresent()) {
  m_fileChooser.addChoosableFileFilter(m_XStreamFilter);
 }
 m_fileChooser.setFileFilter(m_binaryFilter);
}

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

private JFileChooser criarSeletorPlugin() {
  JFileChooser dialogoSelecaoArquivo = FabricaDeFileChooser.getFileChooserAbertura();
  dialogoSelecaoArquivo.setCurrentDirectory(new File(Configuracoes.getInstancia().getCaminhoUltimoDiretorio()));
  dialogoSelecaoArquivo.setMultiSelectionEnabled(true);
  dialogoSelecaoArquivo.setAcceptAllFileFilterUsed(false);
  dialogoSelecaoArquivo.addChoosableFileFilter(filtroPlugins);
  dialogoSelecaoArquivo.setFileFilter(filtroPlugins);
  return dialogoSelecaoArquivo;
}

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

JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.setFileFilter(
  new FileFilter() {
 File theFileToSave = fileChooser.getSelectedFile();
 try {
  CSVExporter.writeCSVColumns(

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

@Override
public void actionPerformed(ActionEvent event) {
  final JFileChooser fileChooser = new JFileChooser(model.getLastDirectory());
  final FileFilter filter = new JavaFileFilter();
  fileChooser.setFileFilter(filter);
  final int returnCode = fileChooser.showOpenDialog(MainFrame.this);
  if (returnCode == JFileChooser.APPROVE_OPTION) {
    final File file = fileChooser.getSelectedFile();
    openFile(file);
  }
}

相关文章

JFileChooser类方法