Java JButton Settings selectFile(final int openMode, final String title, final String buttonText, final String lastDirectoryUsed, final Component parent, final String suffix, final String description)

Here you can find the source of selectFile(final int openMode, final String title, final String buttonText, final String lastDirectoryUsed, final Component parent, final String suffix, final String description)

Description

Function to open a JFileChooser and set it properly.

License

Open Source License

Return

a File object if one has been chosen. Null otherwise.

Declaration

public static File selectFile(final int openMode, final String title, final String buttonText,
        final String lastDirectoryUsed, final Component parent, final String suffix, final String description) 

Method Source Code


//package com.java2s;
import java.awt.Component;
import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    /**/*from w  w w.j av  a  2s.  c  o  m*/
     * Function to open a JFileChooser and set it properly.
     *
     * @return a File object if one has been chosen. Null otherwise.
     */
    public static File selectFile(final int openMode, final String title, final String buttonText,
            final String lastDirectoryUsed, final Component parent, final String suffix, final String description) {
        JFileChooser chooser = new JFileChooser(lastDirectoryUsed);
        chooser.setFileHidingEnabled(false);
        chooser.setDialogTitle(title);
        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory()) {
                    return true;
                }
                return pathname.getName().endsWith(suffix);
            }

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

        int returnVal = chooser.showDialog(parent, buttonText);
        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return null;
        }
        return chooser.getSelectedFile();
    }
}

Related

  1. removeListeners(AbstractButton button)
  2. scaleAllAbstractButtonIconsOf(Container container, int size)
  3. scaleButtonIcon(Icon icon, int size)
  4. ScaleButtonIcon(JToggleButton btn, int width, int height, int fontsize)
  5. SelectedOptionButton(Container container)
  6. selectWithoutNotifyingListeners(AbstractButton ab, boolean selected)
  7. setAction(AbstractButton btn, ActionListener listener, String actionCommand)
  8. setAllEnabled(final ButtonGroup buttonGroup, final boolean enabled)
  9. setAutoMnemonic(AbstractButton button)