Class FileChooser

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class FileChooser extends JFileChooser
A custom file chooser dialog for selecting files or directories with localization support.

This class extends JFileChooser and provides additional functionality such as:

  • Customizable UI text and tooltips through a LocaleManager.
  • Support for filtering files by extension.
  • Customizable dialog properties like title, selection mode, and description messages.
  • Automatic application of localized text to the file chooser components.

Example usage:

 LocaleManager localeManager = new LocaleManager();
 FileChooser fileChooser = new FileChooser(
     System.getProperty("user.home"),
     "Select a File",
     true,
     localeManager
 );
 int result = fileChooser.showOpenDialog(null);
 if (result == JFileChooser.APPROVE_OPTION) {
     File selectedFile = fileChooser.getSelectedFile();
     System.out.println("Selected file: " + selectedFile.getAbsolutePath());
 }
 
See Also:
  • Constructor Details

    • FileChooser

      public FileChooser(String path, String dialogTitle, LocaleManager localeManager)
      Create a generic file chooser dialog allowing selection of both files and directories.
      Parameters:
      path - The directory to open the dialog in.
      dialogTitle - The title of the dialog.
      localeManager - the locale manager to use for the file chooser
    • FileChooser

      public FileChooser(String path, String dialogTitle, boolean selectFiles, LocaleManager localeManager)
      Create a file chooser dialog for selecting files or directories.
      Parameters:
      path - The directory to open the dialog in.
      dialogTitle - The title of the dialog.
      selectFiles - Whether to show files in the dialog. If false, only directories will be shown.
      localeManager - the locale manager to use for the file chooser
    • FileChooser

      public FileChooser(String path, String dialogTitle, String extension, LocaleManager localeManager)
      Create a file chooser dialog for selecting files matching a file extension.
      Parameters:
      path - The directory to open the dialog in.
      dialogTitle - The title of the dialog.
      extension - The extension to filter files by. ex. "txt"
      localeManager - the locale manager to use for the file chooser
    • FileChooser

      public FileChooser(String path, String dialogTitle, boolean selectFiles, String customMessage, LocaleManager localeManager)
      Create a file chooser dialog for selecting files or directories that uses a custom description message.
      Parameters:
      path - The directory to open the dialog in.
      dialogTitle - The title of the dialog.
      selectFiles - Whether to show files in the dialog. If false, only directories will be shown.
      customMessage - Custom message to show in the description area.
      localeManager - the locale manager to use for the file chooser
    • FileChooser

      public FileChooser(String path, String dialogTitle, boolean selectFiles, boolean selectDirectories, boolean filterByExtension, String extension, boolean useCustomMessage, String customMessage, LocaleManager localeManager)
      Create a file chooser dialog.
      Parameters:
      path - The directory to open the dialog in.
      dialogTitle - The title of the dialog.
      selectFiles - Whether to show files in the dialog.
      selectDirectories - Whether to show directories in the dialog.
      filterByExtension - Whether to filter files by extension.
      extension - The extension to filter files by. Dependent on filterByExtension. ex. "txt"
      useCustomMessage - whether to use a custom message for the description
      customMessage - the message to use for custom message
      localeManager - the locale manager to use for the file chooser