Class Popups
java.lang.Object
nl.colorize.util.swing.Popups
Utility class for working with pop-up modal dialog windows in Swing
applications.
There are two ways to create pop-up windows: By using builder()
and its methods to configure and show the pop-up window, or by using one
of the "pre-baked" static methods that create a pop-up dialog in one go.
Both approaches wrap the underlying JOptionPane. It makes sure
that pop-up windows look native on each platform, automatically word-wraps
long messages, and provides a number of convenience methods.
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic Popupsbuilder()Starts building a new pop-up window.static voiderrorMessage(JFrame parent, String message) Shows a simple pop-up window that displays an error message with a generic "Error" title and a single "OK" button.static voidShows a simple pop-up window that displays a text message and contains a default "OK" button.static voidShows a simple pop-up window that displays a text message and contains a default "OK" button.static intShows a pop-up window that consists of the specified component and a number of buttons.static intShows a pop-up window that consists of the specified component and a number of buttons.static voidmessage(JFrame parent, String title, JComponent message) Shows a simple pop-up window that displays a component and contains a default "OK" button.static intmessage(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 intShows a pop-up window that consists of the specified component and a number of buttons.intshow()Displays a pop-up window based on the configuration in this builder.intDisplays a pop-up window based on the configuration in this builder.withButtons(String... buttonLabels) withButtons(List<String> buttonLabels) withMessage(String message) withPanel(JComponent panel)
-
Field Details
-
MESSAGE_WIDTH
public static final int MESSAGE_WIDTH- See Also:
-
-
Method Details
-
withTitle
-
withButtons
-
withButtons
-
withConfirmButtons
-
withPanel
-
withMessage
-
withWarningIcon
-
withErrorIcon
-
show
Displays a pop-up window based on the configuration in this builder. The pop-up window will be modal for the specified parent window.- Returns:
- The index of the button that was clicked. Returns -1 if the pop-up window was disposed of without explicitly clicking one of its buttons.
-
show
public int show()Displays a pop-up window based on the configuration in this builder. The pop-up window will be modal for the entire application.- Returns:
- The index of the button that was clicked. Returns -1 if the pop-up window was disposed of without explicitly clicking one of its buttons.
-
builder
Starts building a new pop-up window. The initial state will have no title, an empty message, and a single default "OK" button. -
message
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
buttonswas clicked this will return 0. - Throws:
IllegalArgumentException- if no buttons were supplied.
-
message
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
buttonswas clicked this will return 0. - Throws:
IllegalArgumentException- if no buttons were supplied.
-
message
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
buttonswas clicked this will return 0. - Throws:
IllegalArgumentException- if no buttons were supplied.
-
message
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
buttonswas clicked this will return 0. - Throws:
IllegalArgumentException- if no buttons were supplied.
-
message
Shows a simple pop-up window that displays a component and contains a default "OK" button. -
message
-
message
-
errorMessage
-