public final class FxUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> void |
bind(javafx.collections.ObservableList<? super T> list,
javafx.beans.value.ObservableValue<? extends java.util.List<? extends T>> observable)
Binds an observable list to a list property.
|
static <T> void |
bind(javafx.beans.property.Property<T> property,
DataSource<T> dataSource)
Binds a property to the data of a data source.
|
static <K,V,T> void |
bind(javafx.beans.property.Property<T> property,
javafx.collections.ObservableMap<K,V> map,
K key,
java.util.function.Function<V,T> converter)
Binds a property to the value of an entry in a map.
|
static <T> void |
bindBidirectional(javafx.beans.property.Property<T> property,
DataSource<T> dataSource)
Bidirectionally binds a property and a data source.
|
static <T> T |
getController(javafx.scene.Node node)
Gets the FXML controller for a node.
|
static java.util.Optional<javafx.scene.control.Label> |
getLabel(javafx.scene.Node node)
Gets the label associated with a node.
|
static <N extends javafx.scene.Node> |
load(java.lang.Class<?> controllerClass)
Loads an FXML file specified by its controller class'
ParametrizedController annotation. |
static javafx.scene.control.MenuItem |
menuItem(java.lang.String text,
javafx.event.EventHandler<javafx.event.ActionEvent> eventHandler)
Creates a menu item with the given text and event handler.
|
static javafx.scene.control.MenuItem |
menuLabel(java.lang.String text)
Creates a disabled menu item for use as a label.
|
static void |
requestClose(javafx.stage.Window window)
Fires a close request on a window.
|
static java.util.concurrent.CompletableFuture<java.lang.Boolean> |
runOnFxThread(java.lang.Runnable task)
Runs a task on the JavaFX application thread as soon as possible.
|
static void |
setController(javafx.scene.Node node,
java.lang.Object controller)
Sets the FXML controller for a node.
|
static java.lang.String |
toHexString(javafx.scene.paint.Color color)
Converts a JavaFX color to a hex web string in the format
#RRGGBBAA . |
static javafx.beans.binding.When |
when(javafx.beans.property.Property<java.lang.Boolean> condition)
A more general version of
Bindings.when(ObservableBooleanValue)
that can accept general boolean properties as conditions. |
public static java.util.concurrent.CompletableFuture<java.lang.Boolean> runOnFxThread(java.lang.Runnable task)
task
- the task to run. If null, the method will return immediately and no action
will be taken.true
once the task has runpublic static <K,V,T> void bind(javafx.beans.property.Property<T> property, javafx.collections.ObservableMap<K,V> map, K key, java.util.function.Function<V,T> converter)
K
- the type of keys in the mapV
- the type of values in the mapT
- the type of data in the propertyproperty
- the property to bindmap
- the map to bind tokey
- the key of the entry to bind toconverter
- a function for converting map values to a type the property can acceptpublic static <T> void bind(javafx.beans.property.Property<T> property, DataSource<T> dataSource)
T
- the type of data of the sourceproperty
- the property to binddataSource
- the data source to bind topublic static <T> void bind(javafx.collections.ObservableList<? super T> list, javafx.beans.value.ObservableValue<? extends java.util.List<? extends T>> observable)
T
- the type of elements in the listlist
- the observable list to bindobservable
- the property to bind topublic static <T> void bindBidirectional(javafx.beans.property.Property<T> property, DataSource<T> dataSource)
T
- the type of dataproperty
- the property to binddataSource
- the data source to bindpublic static javafx.beans.binding.When when(javafx.beans.property.Property<java.lang.Boolean> condition)
Bindings.when(ObservableBooleanValue)
that can accept general boolean properties as conditions.condition
- the condition to bind toBindings.when(ObservableBooleanValue)
public static java.lang.String toHexString(javafx.scene.paint.Color color)
#RRGGBBAA
. The string can be read with
Color.web
to create a Color
object that the string represents.color
- the color to convert to a hex string.public static javafx.scene.control.MenuItem menuItem(java.lang.String text, javafx.event.EventHandler<javafx.event.ActionEvent> eventHandler)
text
- the text of the menu itemeventHandler
- the handler to call when the menu item is acted uponpublic static javafx.scene.control.MenuItem menuLabel(java.lang.String text)
text
- the text of the labelpublic static java.util.Optional<javafx.scene.control.Label> getLabel(javafx.scene.Node node)
node
- the node to get the label forpublic static void setController(javafx.scene.Node node, java.lang.Object controller)
node
- the node to set the controller forcontroller
- the FXML controller for the nodepublic static <T> T getController(javafx.scene.Node node)
T
- the type of the controllernode
- the node to get the FXML controller ofjava.util.NoSuchElementException
- if no FXML controller has been set for the given nodejava.lang.ClassCastException
- if the FXML controller has been set to a controller not of type T
public static <N extends javafx.scene.Node> N load(java.lang.Class<?> controllerClass) throws java.lang.IllegalArgumentException, java.io.IOException
ParametrizedController
annotation.controllerClass
- the FXML controller class to loadjava.lang.IllegalArgumentException
- if the class does not have a ParametrizedController
annotationjava.io.IOException
- if the specified FXML file could not be loadedpublic static void requestClose(javafx.stage.Window window)
window
- the window to request to close