public class Snackbar extends Message
Snackbars can also offer the ability to perform an action, such as undoing an action that was just taken,
or retrying an action that had failed. The action needs to have a name and should be specified by passing
a String to setActionText(String)
. The action can be set via setOnAction(EventHandler)
.
Message.LENGTH_LONG
.
The following code creates a Button and a Snackbar and in the event handler of the button calls show()
to show the Snackbar.
Button button = new Button("Click");
Snackbar snackbar = new Snackbar("This is a Message!", "Action", e -> System.out.println("Action Pressed"));
button.setOnAction(event -> snackbar.show());
Type | Property and Description |
---|---|
javafx.beans.property.StringProperty |
actionText
Text to be displayed beside the message on the Snackbar.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<javafx.event.ActionEvent>> |
onAction
Action to be performed by the action text of the Snackbar.
|
LENGTH_LONG, LENGTH_SHORT
Constructor and Description |
---|
Snackbar(java.lang.String message)
Creates a new instance of Snackbar with the provided message.
|
Snackbar(java.lang.String message,
java.lang.String actionText,
javafx.event.EventHandler<javafx.event.ActionEvent> eventHandler)
Creates a new instance of Snackbar with the provided message
and a button.
|
Modifier and Type | Method and Description |
---|---|
javafx.beans.property.StringProperty |
actionTextProperty()
Text to be displayed beside the message on the Snackbar.
|
void |
cancel()
If the Message is currently showing, calling this method will hide it immediately
and show the next Message in queue.
|
java.lang.String |
getActionText()
Gets the value of the property actionText.
|
javafx.event.EventHandler<javafx.event.ActionEvent> |
getOnAction()
Gets the value of the property onAction.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<javafx.event.ActionEvent>> |
onActionProperty()
Action to be performed by the action text of the Snackbar.
|
void |
setActionText(java.lang.String value)
Sets the value of the property actionText.
|
void |
setOnAction(javafx.event.EventHandler<javafx.event.ActionEvent> value)
Sets the value of the property onAction.
|
void |
show()
Shows the Message immediately, if no other message is showing.
|
durationProperty, getDuration, getId, getMessage, idProperty, messageProperty, setDuration, setId, setMessage
public final javafx.beans.property.StringProperty actionTextProperty
setOnAction(EventHandler)
is fired.getActionText()
,
setActionText(String)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<javafx.event.ActionEvent>> onActionProperty
button text
is provided, or if empty string is provided.getOnAction()
,
setOnAction(EventHandler)
public Snackbar(java.lang.String message)
message
- Message to be show on the snackbar.public Snackbar(java.lang.String message, java.lang.String actionText, javafx.event.EventHandler<javafx.event.ActionEvent> eventHandler)
message
- Message to be show on the snackbar.actionText
- Text for the action..eventHandler
- Action to be performed by the button.public final javafx.beans.property.StringProperty actionTextProperty()
setOnAction(EventHandler)
is fired.getActionText()
,
setActionText(String)
public final java.lang.String getActionText()
setOnAction(EventHandler)
is fired.public final void setActionText(java.lang.String value)
setOnAction(EventHandler)
is fired.public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<javafx.event.ActionEvent>> onActionProperty()
button text
is provided, or if empty string is provided.getOnAction()
,
setOnAction(EventHandler)
public final javafx.event.EventHandler<javafx.event.ActionEvent> getOnAction()
button text
is provided, or if empty string is provided.public final void setOnAction(javafx.event.EventHandler<javafx.event.ActionEvent> value)
button text
is provided, or if empty string is provided.public void show()
public void cancel()