public class Notification extends java.lang.Object
NotificationManager
is responsible for building the message panel and displaying it on screen.
example:
Notification note = new Notification("Hi there!"); note.setIcon(JOptionPane.INFORMATION_MESSAGE); // optional note.setDuration(Notification.TIME_SHORT); // optional note.show();
Modifier and Type | Field and Description |
---|---|
private java.awt.Component |
content |
static int |
DEFAULT_CONTENT_WIDTH |
private int |
duration |
private java.lang.String |
helpTopic |
private javax.swing.Icon |
icon |
static int |
TIME_DEFAULT
Short message of one or two lines (5 s).
|
static int |
TIME_LONG
Somewhat longer message (10 s).
|
static int |
TIME_SHORT
Very short and very easy to grasp message (3 s).
|
static int |
TIME_VERY_LONG
Long text.
|
Constructor and Description |
---|
Notification()
Constructs a new
Notification without content. |
Notification(java.lang.String msg)
Constructs a new
Notification with the given textual content. |
Modifier and Type | Method and Description |
---|---|
java.awt.Component |
getContent() |
int |
getDuration() |
java.lang.String |
getHelpTopic() |
javax.swing.Icon |
getIcon() |
Notification |
setContent(java.awt.Component content)
Set the content of the message.
|
Notification |
setContent(java.lang.String msg)
Set the notification text.
|
Notification |
setDuration(int duration)
Set the time after which the message is hidden.
|
Notification |
setHelpTopic(java.lang.String helpTopic)
Display a help button at the bottom of the notification window.
|
Notification |
setIcon(javax.swing.Icon icon)
Set an icon to display on the left part of the message window.
|
Notification |
setIcon(int messageType)
Set an icon to display on the left part of the message window by
choosing from the default JOptionPane icons.
|
void |
show()
Display the notification.
|
public static final int DEFAULT_CONTENT_WIDTH
public static final int TIME_SHORT
public static final int TIME_DEFAULT
public static final int TIME_LONG
public static final int TIME_VERY_LONG
private java.awt.Component content
private int duration
private javax.swing.Icon icon
private java.lang.String helpTopic
public Notification()
Notification
without content.public Notification(java.lang.String msg)
Notification
with the given textual content.msg
- The text to displaypublic Notification setContent(java.awt.Component content)
content
- any Component to be shownsetContent(java.lang.String)
public Notification setContent(java.lang.String msg)
msg
- the message String. Will be wrapped in <html>, so
you can use <br> and other markup directly.Notification(java.lang.String)
public Notification setDuration(int duration)
duration
- the time (in milliseconds)
Preset values TIME_SHORT
, TIME_DEFAULT
, TIME_LONG
and TIME_VERY_LONG
can be used.public Notification setIcon(javax.swing.Icon icon)
icon
- the icon (null means no icon is displayed)public Notification setIcon(int messageType)
messageType
- one of the following: JOptionPane.ERROR_MESSAGE,
JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE,
JOptionPane.QUESTION_MESSAGE, JOptionPane.PLAIN_MESSAGEpublic Notification setHelpTopic(java.lang.String helpTopic)
helpTopic
- the help topicpublic java.awt.Component getContent()
public int getDuration()
public javax.swing.Icon getIcon()
public java.lang.String getHelpTopic()
public void show()