- java.lang.Object
-
- com.gluonhq.charm.glisten.control.Message
-
- com.gluonhq.charm.glisten.control.Snackbar
-
public class Snackbar extends Message
Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. They provides brief feedback about an operation through a message at the bottom of the screen.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
Default duration for Snackbars issetActionText(String)
. The action can be set viasetOnAction(EventHandler)
.Message.LENGTH_LONG
.Example
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());
- Since:
- 5.0.0
-
-
Property Summary
Properties Type Property Description StringProperty
actionText
Text to be displayed beside the message on the Snackbar.ObjectProperty<EventHandler<ActionEvent>>
onAction
Action to be performed by the action text of the Snackbar.
-
Field Summary
-
Fields inherited from class com.gluonhq.charm.glisten.control.Message
LENGTH_LONG, LENGTH_SHORT
-
-
Constructor Summary
Constructors Constructor Description Snackbar(String message)
Creates a new instance of Snackbar with the provided message.Snackbar(String message, String actionText, EventHandler<ActionEvent> eventHandler)
Creates a new instance of Snackbar with the provided message and a button.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.String
getActionText()
Gets the value of the property actionText.EventHandler<ActionEvent>
getOnAction()
Gets the value of the property onAction.ObjectProperty<EventHandler<ActionEvent>>
onActionProperty()
Action to be performed by the action text of the Snackbar.void
setActionText(String value)
Sets the value of the property actionText.void
setOnAction(EventHandler<ActionEvent> value)
Sets the value of the property onAction.void
show()
Shows the Message immediately, if no other message is showing.-
Methods inherited from class com.gluonhq.charm.glisten.control.Message
durationProperty, getDuration, getId, getMessage, idProperty, messageProperty, setDuration, setId, setMessage
-
-
-
-
Property Detail
-
actionText
public final StringProperty actionTextProperty
Text to be displayed beside the message on the Snackbar. When the text is clicked, the action provided viasetOnAction(EventHandler)
is fired.- See Also:
getActionText()
,setActionText(String)
-
onAction
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty
Action to be performed by the action text of the Snackbar. Note: The button won't be visible if nobutton text
is provided, or if empty string is provided.- See Also:
getOnAction()
,setOnAction(EventHandler)
-
-
Constructor Detail
-
Snackbar
public Snackbar(String message)
Creates a new instance of Snackbar with the provided message.- Parameters:
message
- Message to be show on the snackbar.
-
Snackbar
public Snackbar(String message, String actionText, EventHandler<ActionEvent> eventHandler)
Creates a new instance of Snackbar with the provided message and a button.- Parameters:
message
- Message to be show on the snackbar.actionText
- Text for the action..eventHandler
- Action to be performed by the button.
-
-
Method Detail
-
actionTextProperty
public final StringProperty actionTextProperty()
Text to be displayed beside the message on the Snackbar. When the text is clicked, the action provided viasetOnAction(EventHandler)
is fired.- See Also:
getActionText()
,setActionText(String)
-
getActionText
public final String getActionText()
Gets the value of the property actionText.- Property description:
- Text to be displayed beside the message on the Snackbar.
When the text is clicked, the action provided via
setOnAction(EventHandler)
is fired.
-
setActionText
public final void setActionText(String value)
Sets the value of the property actionText.- Property description:
- Text to be displayed beside the message on the Snackbar.
When the text is clicked, the action provided via
setOnAction(EventHandler)
is fired.
-
onActionProperty
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()
Action to be performed by the action text of the Snackbar. Note: The button won't be visible if nobutton text
is provided, or if empty string is provided.- See Also:
getOnAction()
,setOnAction(EventHandler)
-
getOnAction
public final EventHandler<ActionEvent> getOnAction()
Gets the value of the property onAction.- Property description:
- Action to be performed by the action text of the Snackbar.
Note: The button won't be visible if no
button text
is provided, or if empty string is provided.
-
setOnAction
public final void setOnAction(EventHandler<ActionEvent> value)
Sets the value of the property onAction.- Property description:
- Action to be performed by the action text of the Snackbar.
Note: The button won't be visible if no
button text
is provided, or if empty string is provided.
-
show
public void show()
Shows the Message immediately, if no other message is showing. If a message is already showing, it gets added to the waiting queue and will show when its turn arrives.
-
cancel
public void cancel()
If the Message is currently showing, calling this method will hide it immediately and show the next Message in queue. If the Message is waiting in the queue, calling this method removes the Message from the queue and the Message is never shown.
-
-