public final class Borders
extends java.lang.Object
Nodes with a border,
in a way somewhat analogous to the Swing BorderFactory (although with
less options as a lot of what the Swing BorderFactory offers resulted in
ugly borders!).
The Borders class provides a fluent API for specifying the properties of
each border. It is possible to create multiple borders around a Node simply
by continuing to call additional methods before you call the final
build() method. To use the Borders class, you simply call
wrap(Node), passing in the Node you wish to wrap the border(s)
around.
Firstly, lets wrap a JavaFX Button node with a simple line border that looks
like the following:

Here's the code:
Button button = new Button("Hello World!");
Node wrappedButton = Borders.wrap(button).lineBorder().buildAll();
Easy, isn't it!? You can make the border look a little nicer by replacing
the line border with an etched border. An etched border
has a subtle inner (or outer) line that makes the border stand out a bit more,
like this:

Now that's one good looking border! Here's the code:
Button button = new Button("Hello World!");
Node wrappedButton = Borders.wrap(button).etchedBorder().buildAll();
In some circumstances you want to have multiple borders. For example,
you might two line borders. That's easy:

Node wrappedButton = Borders.wrap(button)
.lineBorder().color(Color.RED).build()
.lineBorder().color(Color.GREEN).build()
.build();
You simply chain the borders together, going from inside to outside!
Because of all the configuration options it isn't possible to list all the functionality of all the border types, so refer to the rest of the javadocs for inspiration.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Borders.Border
The public interface used by the
Borders API to wrap nodes with
zero or more Border implementations. |
class |
Borders.EmptyBorders
A fluent API that is only indirectly instantiable via the
Borders
fluent API, and which allows for an empty border
to be wrapped around a given Node. |
class |
Borders.EtchedBorders
A fluent API that is only indirectly instantiable via the
Borders
fluent API, and which allows for an etched border
to be wrapped around a given Node. |
class |
Borders.LineBorders
A fluent API that is only indirectly instantiable via the
Borders
fluent API, and which allows for a line border
to be wrapped around a given Node. |
| Modifier and Type | Method and Description |
|---|---|
Borders |
addBorder(Borders.Border border)
Allows for developers to develop custom
Border implementations,
and to wrap them around a Node. |
javafx.scene.Node |
build()
Returns the original node wrapped in zero or more borders, as specified
using the fluent API.
|
Borders.EmptyBorders |
emptyBorder()
Often times it is useful to have a bit of whitespace around a Node, to
separate it from what it is next to.
|
Borders.EtchedBorders |
etchedBorder()
The etched border look is essentially equivalent to the
lineBorder()
look, except rather than one line, there are two. |
Borders.LineBorders |
lineBorder()
Creates a nice, simple border around the node.
|
static Borders |
wrap(javafx.scene.Node n)
Fluent API entry method(s)
|
public static Borders wrap(javafx.scene.Node n)
public Borders.EmptyBorders emptyBorder()
public Borders.EtchedBorders etchedBorder()
lineBorder()
look, except rather than one line, there are two. What is commonly done in
this circumstance is that one of the lines is a very light colour (commonly
white), which gives a nice etched look. Refer to the API in Borders.EtchedBorders
for more information.public Borders.LineBorders lineBorder()
Borders.LineBorders, so explore it carefully.public Borders addBorder(Borders.Border border)
Border implementations,
and to wrap them around a Node. Note that of course this is mostly
redundant (as you could just call Border#wrap(Node) directly).
The only benefit is if you're creating a compound border consisting of
multiple borders, and you want your custom border included as part of
this.public javafx.scene.Node build()