Class Popups

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

public final class Popups extends Object
Utility class for working with pop-up windows. This class can be used instead of calling JOptionPane directly. It makes sure that dialogs look native on each platform, automatically word-wraps long messages, and provides a number of convenience methods. Like JOptionPane, pop-up windows can specify a parent window or pass null to be considered as global for the entire application.

It's recommended to not rely on generic button labels such as "OK" or "cancel", since they can be confusing depending on the action performed by the pop-up window. Instead, try to use button labels that convey the action that is going to be performed, such as "save" or "download file".

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    confirmMessage(JFrame parent, String message)
    Shows a simple pop-up window that displays a text message and contains default "OK" and "cancel" buttons.
    static boolean
    confirmMessage(JFrame parent, String title, JComponent message)
    Shows a simple pop-up window that displays a text message and contains default "OK" and "cancel" buttons.
    static void
    message(JFrame parent, String message)
    Shows a simple pop-up window that displays a text message and contains a default "OK" button.
    static void
    message(JFrame parent, String title, String message)
    Shows a simple pop-up window that displays a text message and contains a default "OK" button.
    static int
    message(JFrame parent, String title, String message, String... buttons)
    Shows a pop-up window that consists of the specified component and a number of buttons.
    static int
    message(JFrame parent, String title, String message, List<String> buttons)
    Shows a pop-up window that consists of the specified component and a number of buttons.
    static void
    message(JFrame parent, String title, JComponent message)
    Shows a simple pop-up window that displays a component and contains a default "OK" button.
    static int
    message(JFrame parent, String title, JComponent panel, String... buttons)
    Shows a pop-up window that consists of the specified component and a number of buttons.
    static int
    message(JFrame parent, String title, JComponent panel, List<String> buttons)
    Shows a pop-up window that consists of the specified component and a number of buttons.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • message

      public static int message(JFrame parent, String title, JComponent panel, List<String> buttons)
      Shows a pop-up window that consists of the specified component and a number of buttons. The first button in the list is considered the "primary" button. This method will block until either one of the buttons is clicked or the dialog was cancelled.
      Returns:
      The index of the button that was clicked. For example, if the first button from buttons was clicked this will return 0.
      Throws:
      IllegalArgumentException - if no buttons were supplied.
    • message

      public static int message(JFrame parent, String title, JComponent panel, String... buttons)
      Shows a pop-up window that consists of the specified component and a number of buttons. The first button in the list is considered the "primary" button. This method will block until either one of the buttons is clicked or the dialog was cancelled.
      Returns:
      The index of the button that was clicked. For example, if the first button from buttons was clicked this will return 0.
      Throws:
      IllegalArgumentException - if no buttons were supplied.
    • message

      public static int message(JFrame parent, String title, String message, List<String> buttons)
      Shows a pop-up window that consists of the specified component and a number of buttons. The first button in the list is considered the "primary" button. This method will block until either one of the buttons is clicked or the dialog was cancelled.
      Returns:
      The index of the button that was clicked. For example, if the first button from buttons was clicked this will return 0.
      Throws:
      IllegalArgumentException - if no buttons were supplied.
    • message

      public static int message(JFrame parent, String title, String message, String... buttons)
      Shows a pop-up window that consists of the specified component and a number of buttons. The first button in the list is considered the "primary" button. This method will block until either one of the buttons is clicked or the dialog was cancelled.
      Returns:
      The index of the button that was clicked. For example, if the first button from buttons was clicked this will return 0.
      Throws:
      IllegalArgumentException - if no buttons were supplied.
    • message

      public static void message(JFrame parent, String title, JComponent message)
      Shows a simple pop-up window that displays a component and contains a default "OK" button.
    • message

      public static void message(JFrame parent, String title, String message)
      Shows a simple pop-up window that displays a text message and contains a default "OK" button.
    • message

      public static void message(JFrame parent, String message)
      Shows a simple pop-up window that displays a text message and contains a default "OK" button.
    • confirmMessage

      public static boolean confirmMessage(JFrame parent, String title, JComponent message)
      Shows a simple pop-up window that displays a text message and contains default "OK" and "cancel" buttons.
      Returns:
      True when OK, false when cancelled.
    • confirmMessage

      public static boolean confirmMessage(JFrame parent, String message)
      Shows a simple pop-up window that displays a text message and contains default "OK" and "cancel" buttons.
      Returns:
      True when OK, false when cancelled.