Package swingtree.dialogs
Class ConfirmDialog
java.lang.Object
swingtree.dialogs.ConfirmDialog
An immutable builder class for creating simple confirmation dialogs
based on the
JOptionPane
class, more specifically the
JOptionPane.showOptionDialog(Component, Object, String, int, int, Icon, Object[], Object)
method.
This class is intended to be used as part of the UI
API
by calling the UIFactoryMethods.confirmation(String)
factory method.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConfirmDialog
Creates a newConfirmDialog
instance with the specified question.cancelOption
(String cancelOption) This method allows you to specify some text that will be used to represent theConfirmAnswer.CANCEL
option in the dialog.defaultOption
(ConfirmAnswer defaultOption) Use this to specify the default option for the dialog, which is the option which will have the initial focus when the dialog is shown.Use this to display a custom icon in the dialog by providing the path to the icon resource.Defines the icon for the dialog, whose appearance and position may vary depending on the look and feel of the current system.icon
(IconDeclaration icon) Use this to specify the icon for the confirm dialog through anIconDeclaration
, which is a constant that represents the icon resource with a preferred size.This method allows you to specify some text that will be used to represent theConfirmAnswer.NO
option in the dialog.Allows you to specify the parent component of the dialog, which is the component that the dialog will be centered on top of.show()
Use this to summon the dialog with the current settings and wait for the user to select an option.Shows the confirmation dialog as an error dialog (seeJOptionPane.ERROR_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.Shows the confirmation dialog as an info dialog (seeJOptionPane.INFORMATION_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.Shows the confirmation dialog as a question dialog (seeJOptionPane.QUESTION_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.Shows the confirmation dialog as a warning dialog (seeJOptionPane.WARNING_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.Shows the confirmation dialog as a plain dialog (seeJOptionPane.PLAIN_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.This method allows you to specify the title of the dialog, which is the text that will be displayed in the title bar of the dialog window.This method allows you to specify some text that will be used to represent theConfirmAnswer.YES
option in the dialog.
-
Method Details
-
asking
Creates a newConfirmDialog
instance with the specified question.- Parameters:
question
- The question to ask the user.- Returns:
- A new
ConfirmDialog
instance with the specified question.
-
titled
This method allows you to specify the title of the dialog, which is the text that will be displayed in the title bar of the dialog window. If you don't specify a title, a default title may be used based on the dialog type, so a title does not need to be specified here for the dialog to be shown.- Parameters:
title
- The title of the dialog.- Returns:
- A new
ConfirmDialog
instance with the specified title.
-
yesOption
This method allows you to specify some text that will be used to represent theConfirmAnswer.YES
option in the dialog.
So when the user clicks on that option, the dialog will returnConfirmAnswer.YES
.- Parameters:
yesOption
- The text of the "yes" option.- Returns:
- A new
ConfirmDialog
instance with the specified "yes" option text.
-
noOption
This method allows you to specify some text that will be used to represent theConfirmAnswer.NO
option in the dialog.
So when the user clicks on that option, the dialog will returnConfirmAnswer.NO
.- Parameters:
noOption
- The text of the "no" option.- Returns:
- A new
ConfirmDialog
instance with the specified "no" option text.
-
cancelOption
This method allows you to specify some text that will be used to represent theConfirmAnswer.CANCEL
option in the dialog.
So when the user clicks on that option, the dialog will returnConfirmAnswer.CANCEL
.- Parameters:
cancelOption
- The text of the "cancel" option.- Returns:
- A new
ConfirmDialog
instance with the specified "cancel" option text.
-
defaultOption
Use this to specify the default option for the dialog, which is the option which will have the initial focus when the dialog is shown.
So when the user presses the "Enter" key, the dialog will return the option that was set as the default option.- Parameters:
defaultOption
- The text of the default option.- Returns:
- A new
ConfirmDialog
instance with the specified default option text.
-
icon
Use this to specify the icon for the confirm dialog through anIconDeclaration
, which is a constant that represents the icon resource with a preferred size. The icon will be loaded and cached automatically for you when using the declaration based approach.- Parameters:
icon
- The icon declaration of the dialog, which may contain the path to the icon resource.- Returns:
- A new
ConfirmDialog
instance with the specified icon declaration.
-
icon
Defines the icon for the dialog, whose appearance and position may vary depending on the look and feel of the current system. Consider using theicon(IconDeclaration)
method over this one as it reduces the risk of icon loading issues.- Parameters:
icon
- The icon of the dialog.- Returns:
- A new
ConfirmDialog
instance with the specified icon.
-
icon
Use this to display a custom icon in the dialog by providing the path to the icon resource. Consider using theicon(IconDeclaration)
method over this one as you may also specify the preferred size of the icon through the declaration.- Parameters:
path
- The path to the icon of the dialog.- Returns:
- A new
ConfirmDialog
instance with the specified icon.
-
parent
Allows you to specify the parent component of the dialog, which is the component that the dialog will be centered on top of.
This is useful when you want to make the dialog modal to a specific component, but a parent component is not required to show the dialog.- Parameters:
parent
- The parent component of the dialog.- Returns:
- A new
ConfirmDialog
instance with the specified parent component.
-
showAsQuestion
Shows the confirmation dialog as a question dialog (seeJOptionPane.QUESTION_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.
Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-
showAsError
Shows the confirmation dialog as an error dialog (seeJOptionPane.ERROR_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.
Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-
showAsInfo
Shows the confirmation dialog as an info dialog (seeJOptionPane.INFORMATION_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.
Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-
showAsWarning
Shows the confirmation dialog as a warning dialog (seeJOptionPane.WARNING_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.
Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-
showPlain
Shows the confirmation dialog as a plain dialog (seeJOptionPane.PLAIN_MESSAGE
) and returns theConfirmAnswer
that the user selected in the dialog.
Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-
show
Use this to summon the dialog with the current settings and wait for the user to select an option.
The answer will be returned as aConfirmAnswer
enum. Note that this method is blocking and will only return when the user has selected an option in the dialog.- Returns:
- The
ConfirmAnswer
that the user selected in the dialog.
-