Example usage for javax.swing JFileChooser setAcceptAllFileFilterUsed

List of usage examples for javax.swing JFileChooser setAcceptAllFileFilterUsed

Introduction

In this page you can find the example usage for javax.swing JFileChooser setAcceptAllFileFilterUsed.

Prototype

@BeanProperty(preferred = true, description = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.")
public void setAcceptAllFileFilterUsed(boolean b) 

Source Link

Document

Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.

Usage

From source file:Main.java

private static JFileChooser getXMLfileChooser() {
    JFileChooser fc = new JFileChooser(new File("../comportamientos"));

    // set ExtensionFile...
    fc.setMultiSelectionEnabled(false);/*from ww  w  .j  a  va2 s.co m*/
    fc.setAcceptAllFileFilterUsed(false);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("XML", "xml");
    fc.setFileFilter(filter);

    return fc;
}

From source file:Main.java

/**
 * Consistent way to chosing a file to open with JFileChooser.
 * <p>/*from ww  w.  jav a2  s  .  co m*/
 * 
 * @see JFileChooser#setFileSelectionMode(int)
 * @see #getSystemFiles(Component, int)
 * @param owner to show the component relative to.
 * @param mode selection mode for the JFileChooser.
 * @return File based on the user selection can be null.
 */
public static File getSystemFile(Component owner, int mode, FileFilter[] filters) {

    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(mode);
    jfc.setFileHidingEnabled(true);
    jfc.setAcceptAllFileFilterUsed(true);
    if (filters != null) {
        for (int i = 0; i < filters.length; i++) {
            jfc.addChoosableFileFilter(filters[i]);
        }

        if (filters.length >= 1) {
            jfc.setFileFilter(filters[0]);
        }
    }

    int result = jfc.showOpenDialog(owner);

    if (result == JFileChooser.APPROVE_OPTION) {
        return jfc.getSelectedFile();
    }

    return null;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java

public static JFileChooser createFileChooser(final File dir, final String description, final String extension) {
    JFileChooser fc = new JFileChooser(dir);
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);/* ww w.ja  va  2 s .  c om*/
    fc.setAcceptAllFileFilterUsed(false);
    fc.addChoosableFileFilter(new FileFilter() {

        @Override
        public String getDescription() {
            return description;
        }

        @Override
        public boolean accept(final File f) {
            return f.isDirectory() || FilenameUtils.isExtension(f.getName(), extension);
        }
    });
    return fc;
}

From source file:Main.java

/**
 * Consistent way to chosing multiple files to open with JFileChooser.
 * <p>/*from   w w  w.ja v  a 2s .  co  m*/
 * 
 * @see JFileChooser#setFileSelectionMode(int)
 * @see #getSystemFiles(Component, int)
 * @param owner to show the component relative to.
 * @param mode selection mode for the JFileChooser.
 * @return File[] based on the user selection can be null.
 */
public static File[] getSystemFiles(Component owner, int mode, FileFilter[] filters) {

    JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(mode);
    jfc.setFileHidingEnabled(true);
    jfc.setMultiSelectionEnabled(true);
    jfc.setAcceptAllFileFilterUsed(true);
    if (filters != null) {
        for (int i = 0; i < filters.length; i++) {
            jfc.addChoosableFileFilter(filters[i]);
        }

        if (filters.length >= 1) {
            jfc.setFileFilter(filters[0]);
        }
    }

    int result = jfc.showOpenDialog(owner);
    if (result == JFileChooser.APPROVE_OPTION) {
        return jfc.getSelectedFiles();
    }

    return new File[0];
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java

private static void addExportPopupMenu(final Instances ds, final ChartPanel cp) {
    cp.addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent e) {
            final JPopupMenu jPopupMenu = new JPopupMenu("feur");
            final JMenuItem mi1 = new JMenuItem("Export as CSV");
            mi1.addActionListener(new ActionListener() {
                @Override// ww  w.  j  a v  a 2  s .  c om
                public void actionPerformed(final ActionEvent e) {
                    final JFileChooser fc = new JFileChooser();
                    fc.setAcceptAllFileFilterUsed(false);
                    final int returnVal = fc.showSaveDialog(cp);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        try {
                            final File file = fc.getSelectedFile();
                            WekaDataAccessUtil.saveInstancesIntoCSVFile(ds, file);
                        } catch (final Exception ee) {
                            ee.printStackTrace();
                        }
                    }
                }
            });
            jPopupMenu.add(mi1);
            jPopupMenu.show(cp, e.getTrigger().getX(), e.getTrigger().getY());
        }

        public void chartMouseMoved(ChartMouseEvent e) {
        }
    });
}

From source file:br.univali.ps.fuzzy.portugolFuzzyCorretor.control.FileController.java

public static String getCodigoPortugol() throws FileNotFoundException {
    JFileChooser fc = new JFileChooser(currentDirectory);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Portugol Code", "por", "txt");
    fc.setFileFilter(filter);/*from   w  w w.  ja va 2s  .c  o m*/
    fc.setAcceptAllFileFilterUsed(false);
    File file = null;
    int returnVal = fc.showOpenDialog(null);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = fc.getSelectedFile();
        currentDirectory = file.getParentFile().getPath();
        return formatarArquivoTexto(file);
    }
    return "";
}

From source file:com.willwinder.universalgcodesender.uielements.components.FirmwareSettingsFileTypeFilter.java

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);/*  w  w  w  . j  a v  a  2  s. c o m*/

    return fileChooser;
}

From source file:Main.java

/**
 * Creates a new JFileChooser and returns the selected path's location.
 * @param title/*from   w ww  .  j  a  v a  2s .  com*/
 * @param openTo
 * @param chooseDirectory
 * @param filter
 * @return
 */
public static String getFilePath(String title, String openTo, boolean chooseDirectory, FileFilter filter) {
    String location = null;
    JFileChooser chooser = new JFileChooser(title);
    chooser.setCurrentDirectory(new File(openTo));
    chooser.setFileFilter(filter);
    chooser.setDialogTitle("Open Cache");
    if (chooseDirectory) {
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    } else {
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    }
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(chooser) == JFileChooser.APPROVE_OPTION) {
        location = chooser.getSelectedFile().getAbsolutePath();
    }
    return location;
}

From source file:net.menthor.editor.v2.util.Util.java

public static File chooseFile(Component parent, String lastPath, String dialogTitle, String fileDescription,
        String fileExtension, boolean checkOverrideFile) throws IOException {
    JFileChooser fileChooser = createChooser(lastPath, checkOverrideFile);
    fileChooser.setDialogTitle(dialogTitle);
    FileNameExtensionFilter filter = new FileNameExtensionFilter(fileDescription, fileExtension);
    fileChooser.addChoosableFileFilter(filter);
    if (SystemUtil.onWindows())
        fileChooser.setFileFilter(filter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    if (fileChooser.showDialog(parent, "Ok") == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        if (!file.getName().endsWith("." + fileExtension)) {
            file = new File(file.getCanonicalFile() + "." + fileExtension);
        } else {//from  w ww .  j a  v  a  2  s .  c  o  m
            file = new File(file.getCanonicalFile() + "");
        }
        return file;
    } else {
        return null;
    }
}

From source file:net.menthor.editor.v2.util.Util.java

public static File chooseFile(Component parent, String lastPath, String dialogTitle, String fileDescription,
        String fileExtension, String fileExtension2, boolean checkOverrideFile) throws IOException {
    JFileChooser fileChooser = createChooser(lastPath, checkOverrideFile);
    fileChooser.setDialogTitle(dialogTitle);
    FileNameExtensionFilter filter = new FileNameExtensionFilter(fileDescription, fileExtension,
            fileExtension2);/*w w w . ja  va 2  s  .  co m*/
    fileChooser.addChoosableFileFilter(filter);
    if (SystemUtil.onWindows())
        fileChooser.setFileFilter(filter);
    fileChooser.setAcceptAllFileFilterUsed(false);
    if (fileChooser.showDialog(parent, "Ok") == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        if (!(file.getName().endsWith("." + fileExtension))
                && !(file.getName().endsWith("." + fileExtension2))) {
            file = new File(file.getCanonicalFile() + "." + fileExtension2);
        } else {
            file = new File(file.getCanonicalFile() + "");
        }
        return file;
    } else {
        return null;
    }
}