Class ConfirmDialog

java.lang.Object
swingtree.dialogs.ConfirmDialog

public final class ConfirmDialog extends Object
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 Details

    • asking

      public static ConfirmDialog asking(String question)
      Creates a new ConfirmDialog instance with the specified question.
      Parameters:
      question - The question to ask the user.
      Returns:
      A new ConfirmDialog instance with the specified question.
    • titled

      public ConfirmDialog titled(String title)
      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

      public ConfirmDialog yesOption(String yesOption)
      This method allows you to specify some text that will be used to represent the ConfirmAnswer.YES option in the dialog.
      So when the user clicks on that option, the dialog will return ConfirmAnswer.YES.
      Parameters:
      yesOption - The text of the "yes" option.
      Returns:
      A new ConfirmDialog instance with the specified "yes" option text.
    • noOption

      public ConfirmDialog noOption(String noOption)
      This method allows you to specify some text that will be used to represent the ConfirmAnswer.NO option in the dialog.
      So when the user clicks on that option, the dialog will return ConfirmAnswer.NO.
      Parameters:
      noOption - The text of the "no" option.
      Returns:
      A new ConfirmDialog instance with the specified "no" option text.
    • cancelOption

      public ConfirmDialog cancelOption(String cancelOption)
      This method allows you to specify some text that will be used to represent the ConfirmAnswer.CANCEL option in the dialog.
      So when the user clicks on that option, the dialog will return ConfirmAnswer.CANCEL.
      Parameters:
      cancelOption - The text of the "cancel" option.
      Returns:
      A new ConfirmDialog instance with the specified "cancel" option text.
    • defaultOption

      public ConfirmDialog 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.
      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

      public ConfirmDialog icon(IconDeclaration icon)
      Use this to specify the icon for the confirm dialog through an IconDeclaration, 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

      public ConfirmDialog icon(Icon 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 the icon(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

      public ConfirmDialog icon(String path)
      Use this to display a custom icon in the dialog by providing the path to the icon resource. Consider using the icon(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

      public ConfirmDialog parent(Component 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

      public ConfirmAnswer showAsQuestion()
      Shows the confirmation dialog as a question dialog (see JOptionPane.QUESTION_MESSAGE) and returns the ConfirmAnswer 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

      public ConfirmAnswer showAsError()
      Shows the confirmation dialog as an error dialog (see JOptionPane.ERROR_MESSAGE) and returns the ConfirmAnswer 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

      public ConfirmAnswer showAsInfo()
      Shows the confirmation dialog as an info dialog (see JOptionPane.INFORMATION_MESSAGE) and returns the ConfirmAnswer 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

      public ConfirmAnswer showAsWarning()
      Shows the confirmation dialog as a warning dialog (see JOptionPane.WARNING_MESSAGE) and returns the ConfirmAnswer 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

      public ConfirmAnswer showPlain()
      Shows the confirmation dialog as a plain dialog (see JOptionPane.PLAIN_MESSAGE) and returns the ConfirmAnswer 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

      public ConfirmAnswer 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 a ConfirmAnswer 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.