Class ComboFileDialog

java.lang.Object
nl.colorize.util.swing.ComboFileDialog

public class ComboFileDialog extends Object
A wrapper around both AWT's FileDialog and Swing's JFileChooser. While the Swing file dialog is superior in terms of functionality, its appearance can be far from native dialogs on some platforms. AWT dialogs look like native dialogs, but provide less features. This class will therefore make the tradeoff which file dialog is best for the current platform.
  • Field Details

  • Constructor Details

    • ComboFileDialog

      public ComboFileDialog(String title, File start)
      Creates a file dialog with the specified title and start directory.
      Parameters:
      title - The dialog window's title.
      start - The directory where the dialog will start.
    • ComboFileDialog

      public ComboFileDialog()
      Creates a file dialog with the platform's default dialog title and start directory.
  • Method Details

    • usesSwingDialogs

      public boolean usesSwingDialogs()
      Returns whether file dialogs are created using Swing (if this returns true) or AWT (if this returns false).
    • showOpenDialog

      public File showOpenDialog(JFrame parent)
      Shows an 'open file' dialog and returns the selected file. Returns null if the dialog was cancelled.
      Parameters:
      parent - The parent window for the dialog.
    • showSaveDialog

      public File showSaveDialog(JFrame parent, String extension)
      Shows a 'save file' dialog, and returns the selected file. If the selected file already exists, an extra confirmation dialog is shown to make sure the user wants to overwrite the file. Returns null if the dialog was cancelled.
      Parameters:
      parent - The parent window for the dialog.
      extension - File extension to use if none is entered.
    • setTitle

      public void setTitle(String title)
    • getTitle

      public String getTitle()
    • setStartDirectory

      public void setStartDirectory(File start)
    • setStartDirectory

      public void setStartDirectory(String path)
    • getStartDirectory

      public File getStartDirectory()
    • setFilter

      public void setFilter(String description, String... extensions)
      Sets a filter so that the dialog will only show files with the specified file extension(s).
      Parameters:
      description - A textual description of the filter.
      extensions - An array of file name extensions, such as "png", or "jpg".
      Throws:
      IllegalArgumentException - if the filter has no file extensions.