Top Description Fields Constructors Methods
com.dlsc.gemsfx

public Class EnhancedLabel

extends Label
Class Inheritance
Imports
javafx.beans.property.BooleanProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.css.PseudoClass, javafx.event.ActionEvent, .EventHandler, javafx.scene.Node, javafx.scene.control.ContextMenu, .Label, .MenuItem, javafx.scene.input.Clipboard, .ClipboardContent, .KeyCode, .KeyCodeCombination, .KeyCombination, .MouseButton, java.util.Objects, java.util.function.Supplier

An enhanced label that allows for selecting the (whole) label and copying to the clipboard either via keyboard shortcut or via context menu.

Field Summary

Modifier and TypeField and Description
private final ObjectProperty<Supplier<String>>
private final StringProperty
private ObjectProperty<EventHandler<ActionEvent>>
private final BooleanProperty
private static final PseudoClass

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Supplier<String>>

Returns:

the supplier for the clipboard content when the user copies the label
copyContentSupplierProperty
()

Stores the supplier used for filling the clipboard when the user copies the label.

public final StringProperty

Returns:

the copy menu item name
copyMenuItemTextProperty
()

The text used for the "copy" menu item.

private void
private void
copyText(ActionEvent actionEvent)

public final Supplier<String>
public final String
public final EventHandler<ActionEvent>
public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

private void
init()

public final boolean
public final ObjectProperty<EventHandler<ActionEvent>>

Returns:

the action that is executed when the user copies the label text
onCopyActionProperty
()

The action that is executed when the user copies the label text.

public final BooleanProperty

Returns:

true if the label is selected
selectedProperty
()

Determines whether the label is currently selected or not.

public final void
setCopyContentSupplier(Supplier<String> copyContentSupplier)

public final void
setCopyMenuItemText(String copyMenuItemText)

public final void
public final void
setSelected(boolean selected)

Inherited from javafx.scene.control.Label:
createDefaultSkingetInitialFocusTraversablegetLabelForlabelForPropertysetLabelFor

Field Detail

copyContentSupplierback to summary
private final ObjectProperty<Supplier<String>> copyContentSupplier
copyMenuItemTextback to summary
private final StringProperty copyMenuItemText
onCopyActionback to summary
private ObjectProperty<EventHandler<ActionEvent>> onCopyAction
selectedback to summary
private final BooleanProperty selected
SELECTED_PSEUDO_CLASSback to summary
private static final PseudoClass SELECTED_PSEUDO_CLASS

Constructor Detail

EnhancedLabelback to summary
public EnhancedLabel()
EnhancedLabelback to summary
public EnhancedLabel(String text)
EnhancedLabelback to summary
public EnhancedLabel(String text, Node node)

Method Detail

copyContentSupplierPropertyback to summary
public final ObjectProperty<Supplier<String>> copyContentSupplierProperty()

Stores the supplier used for filling the clipboard when the user copies the label. Sometimes applications want to copy only a part of the label, e.g. an ID shown by the label like this: "Customer account #12345678". The copy content supplier can then decide to just return the ID "12345678" instead of the whole string. The default supplier however returns the whole string.

Returns:ObjectProperty<Supplier<String>>

the supplier for the clipboard content when the user copies the label

copyMenuItemTextPropertyback to summary
public final StringProperty copyMenuItemTextProperty()

The text used for the "copy" menu item.

Returns:StringProperty

the copy menu item name

copyTextback to summary
private void copyText()
copyTextback to summary
private void copyText(ActionEvent actionEvent)
getCopyContentSupplierback to summary
public final Supplier<String> getCopyContentSupplier()
getCopyMenuItemTextback to summary
public final String getCopyMenuItemText()
getOnCopyActionback to summary
public final EventHandler<ActionEvent> getOnCopyAction()
getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
initback to summary
private void init()
isSelectedback to summary
public final boolean isSelected()
onCopyActionPropertyback to summary
public final ObjectProperty<EventHandler<ActionEvent>> onCopyActionProperty()

The action that is executed when the user copies the label text. The default action is to copy the text to the clipboard. This action can be overridden by setting a new event handler.

Returns:ObjectProperty<EventHandler<ActionEvent>>

the action that is executed when the user copies the label text

selectedPropertyback to summary
public final BooleanProperty selectedProperty()

Determines whether the label is currently selected or not.

Returns:BooleanProperty

true if the label is selected

setCopyContentSupplierback to summary
public final void setCopyContentSupplier(Supplier<String> copyContentSupplier)
setCopyMenuItemTextback to summary
public final void setCopyMenuItemText(String copyMenuItemText)
setOnCopyActionback to summary
public final void setOnCopyAction(EventHandler<ActionEvent> value)
setSelectedback to summary
public final void setSelected(boolean selected)