Java Utililty Methods JFileChooser

List of utility methods to do JFileChooser

Description

The list of methods to do JFileChooser are organized into topic(s).

Method

FilegetFile(FileFilter filter)
get File
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    return chooser.getSelectedFile();
return null;
StringgetFile(String initialPath, final String extension, String TitleText)
get File
final String ext = extension.replace("*", "");
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File(initialPath));
chooser.setDialogTitle(TitleText);
FileFilter filter = new FileFilter() {
    @Override
    public String getDescription() {
        return extension;
...
File[]getFile(String message, boolean isLoadNotSave, File defaultFileOrDir, boolean allowMultipleSelection, String description, final String... extensions)
get File
if (isMac()) {
    java.awt.Frame frame = new java.awt.Frame();
    java.awt.FileDialog chooser = new java.awt.FileDialog(frame, message,
            (isLoadNotSave ? java.awt.FileDialog.LOAD : java.awt.FileDialog.SAVE));
    if (defaultFileOrDir != null) {
        if (defaultFileOrDir.isDirectory()) {
            chooser.setDirectory(defaultFileOrDir.getAbsolutePath());
        } else {
...
FilegetFile(String title, File initialDir)
get File
JFileChooser fChooser = new JFileChooser(initialDir);
fChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fChooser.setDialogTitle(title);
if (fChooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
    return (null);
File c = fChooser.getSelectedFile();
return (c);
JFileChoosergetFileChooser()
get File Chooser
return fileChooser;
JFileChoosergetFileChooser()
get File Chooser
for (Window w : Window.getWindows())
    if (w instanceof JDialog && w.isShowing())
        if (((JDialog) w).getContentPane().getComponent(0) instanceof JFileChooser)
            return (JFileChooser) ((JDialog) w).getContentPane().getComponent(0);
throw new IllegalStateException("no file chooser found!");
JFileChoosergetFileChooser()
get File Chooser
if (chooser == null) {
    chooser = new JFileChooser();
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Otros LogView investigation *.zip.olv";
...
JFileChoosergetFileChooser()
Gets the file chooser.
return chooser;
JFileChoosergetFileChooser()
Returns a JFileChooser with the filter 'All Files'
if (fileChooser == null) {
    fileChooser = new JFileChooser();
    fileChooser.setFileFilter(new FileFilter() {
        @Override
        public String getDescription() {
            return "Alle Dateien";
        @Override
...
JFileChoosergetFileChooser()
get File Chooser
fc.resetChoosableFileFilters();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
return fc;