Package nl.colorize.util.swing
Class ComboFileDialog
java.lang.Object
nl.colorize.util.swing.ComboFileDialog
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 Summary
-
Constructor Summary
ConstructorDescriptionCreates a file dialog with the platform's default dialog title and start directory.ComboFileDialog
(String title, File start) Creates a file dialog with the specified title and start directory. -
Method Summary
Modifier and TypeMethodDescriptiongetTitle()
void
Sets a filter so that the dialog will only show files with the specified file extension(s).void
setStartDirectory
(File start) void
setStartDirectory
(String path) void
showOpenDialog
(JFrame parent) Shows an 'open file' dialog and returns the selected file.showSaveDialog
(JFrame parent, String extension) Shows a 'save file' dialog, and returns the selected file.boolean
Returns whether file dialogs are created using Swing (if this returns true) or AWT (if this returns false).
-
Field Details
-
bundle
-
-
Constructor Details
-
ComboFileDialog
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
Shows an 'open file' dialog and returns the selected file. Returnsnull
if the dialog was cancelled.- Parameters:
parent
- The parent window for the dialog.
-
showSaveDialog
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. Returnsnull
if the dialog was cancelled.- Parameters:
parent
- The parent window for the dialog.extension
- File extension to use if none is entered.
-
setTitle
-
getTitle
-
setStartDirectory
-
setStartDirectory
-
getStartDirectory
-
setFilter
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.
-