Top Description Fields Constructors Methods
org.controlsfx.control

public Class HyperlinkLabel

extends ControlsFXControl
implements EventTarget
Class Inheritance
All Implemented Interfaces
javafx.event.EventTarget
Imports
impl.org.controlsfx.skin.HyperlinkLabelSkin, javafx.beans.property.ObjectProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.event.ActionEvent, .EventHandler, .EventTarget, javafx.scene.control.Hyperlink, .Skin

A UI control that will convert the given text into a series of text labels and hyperlinks, based on the use of delimiter characters to specify where hyperlinks should appear. The delimiter characters are square braces (that is, [ and ]). To create a hyperlink in a string you would therefore do something like hyperlinkLabel.setText("Click [here] for more information!");, with the word 'here' appearing as a hyperlink that a use may click. This approach therefore allows for hyperlinks to be easily embedded within a label.

Once hyperlinks have been declared in a text string, it is necessary to respond to the user interacting with the hyperlink (most commonly via mouse clicks). To do so, you register a single event handler for action events on the HyperlinkLabel instance, and then determine what to do within that callback. For example:

hyperlinkLabel.setOnAction(new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        Hyperlink link = (Hyperlink)event.getSource();
        final String str = link == null ? "" : link.getText();
        switch(str) {
            case "here": // do 'here' action
                         break;
            case "exit": // do exit action
                         break;
        }
    }
});

This simple single-handler approach was chosen over any more complex per-hyperlink solution because it is anticipated that most use cases will normally consist of one, or very few hyperlinks, and it was therefore unlikely that the increased API complexity would be warranted.

Screenshot

To demonstrate what a HyperlinkLabel looks like, refer to the screenshot below, when the text "Hello [world]! I [wonder] what hyperlink [you] [will] [click]" was passed in to the HyperlinkLabel instance:

Screenshot of HyperlinkLabel
See Also
Hyperlink, ActionEvent

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_STYLE_CLASS

* Stylesheet Handling * *

private ObjectProperty<EventHandler<ActionEvent>>
private final StringProperty

Constructor Summary

AccessConstructor and Description
public
HyperlinkLabel()

Creates an empty HyperlinkLabel instance with no text specified.

public
HyperlinkLabel(String
The text to display to the user.
text
)

Creates a HyperlinkLabel instance with the given text value used as the initial text.

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public final EventHandler<ActionEvent>
getOnAction()

Returns: the action, which is invoked whenever a hyperlink is fired.

public final String

Returns:

the text currently displayed.
getText
()

Return the text currently displayed.

public final ObjectProperty<EventHandler<ActionEvent>>

Returns:

an ObjectProperty representing the action.
onActionProperty
()

The action, which is invoked whenever a hyperlink is fired.

public final void
setOnAction(EventHandler<ActionEvent> value)

Sets a new EventHandler which will be invoked whenever a hyperlink is fired.

public final void
setText(String value)

Set a new text to display to the user, using the delimiter characters [ and ] to indicate where hyperlinks should be displayed.

public final StringProperty

Returns:

a StringProperty.
textProperty
()

Return a StringProperty representing the text being displayed.

Inherited from org.controlsfx.control.ControlsFXControl:
getUserAgentStylesheet

Field Detail

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS

* Stylesheet Handling * *

onActionback to summary
private ObjectProperty<EventHandler<ActionEvent>> onAction
textback to summary
private final StringProperty text

Constructor Detail

HyperlinkLabelback to summary
public HyperlinkLabel()

Creates an empty HyperlinkLabel instance with no text specified.

HyperlinkLabelback to summary
public HyperlinkLabel(String text)

Creates a HyperlinkLabel instance with the given text value used as the initial text.

Parameters
text:String

The text to display to the user.

Method Detail

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getOnActionback to summary
public final EventHandler<ActionEvent> getOnAction()
Returns:EventHandler<ActionEvent>

the action, which is invoked whenever a hyperlink is fired.

getTextback to summary
public final String getText()

Return the text currently displayed.

Returns:String

the text currently displayed.

onActionPropertyback to summary
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()

The action, which is invoked whenever a hyperlink is fired. This may be due to the user clicking on the hyperlink with the mouse, or by a touch event, or by a key press.

Returns:ObjectProperty<EventHandler<ActionEvent>>

an ObjectProperty representing the action.

setOnActionback to summary
public final void setOnAction(EventHandler<ActionEvent> value)

Sets a new EventHandler which will be invoked whenever a hyperlink is fired.

setTextback to summary
public final void setText(String value)

Set a new text to display to the user, using the delimiter characters [ and ] to indicate where hyperlinks should be displayed.

textPropertyback to summary
public final StringProperty textProperty()

Return a StringProperty representing the text being displayed.

Returns:StringProperty

a StringProperty.