Class FileTypeFilter

java.lang.Object
com.codename1.io.filechooser.FileTypeFilter

public class FileTypeFilter extends Object

A named group of file types a file dialog offers, such as "PNG Image" or "Text Documents".

A filter can name the same types three ways, and each platform reads the one it understands: desktop dialogs and the fallback chooser use the extensions, Android and the browser use the MIME types, and iOS and macOS use the Uniform Type Identifiers when given, deriving them from the extensions otherwise. Supplying extensions alone works everywhere.

FileTypeFilter png = new FileTypeFilter("PNG Image")
        .extensions("png").mimeTypes("image/png").utTypes("public.png");
  • Constructor Details

    • FileTypeFilter

      public FileTypeFilter(String label)

      Creates a filter with the label the dialog shows for it.

      Parameters
      • label: the human readable name of the filter
  • Method Details

    • extensions

      public FileTypeFilter extensions(String... ext)

      Adds file extensions, with or without the leading dot.

      Parameters
      • ext: extensions such as "png" or ".jpg"
      Returns

      this filter

    • mimeTypes

      public FileTypeFilter mimeTypes(String... types)

      Adds MIME types such as "image/png" or "image/*".

      Parameters
      • types: the MIME types
      Returns

      this filter

    • utTypes

      public FileTypeFilter utTypes(String... types)

      Adds Apple Uniform Type Identifiers such as "public.png". Ignored outside iOS and macOS.

      Parameters
      • types: the type identifiers
      Returns

      this filter

    • getLabel

      public String getLabel()

      The label the dialog shows.

      Returns

      the label

    • getExtensions

      public String[] getExtensions()

      The extensions, without leading dots.

      Returns

      a copy of the extension list

    • getMimeTypes

      public String[] getMimeTypes()

      The MIME types.

      Returns

      a copy of the MIME type list

    • getUtTypes

      public String[] getUtTypes()

      The Uniform Type Identifiers.

      Returns

      a copy of the identifier list

    • acceptsName

      public boolean acceptsName(String name)

      Checks whether a file name ends with one of this filter's extensions. A filter without extensions accepts every name.

      Parameters
      • name: the file name or path
      Returns

      true if the name matches