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.
Examples
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The public interface used by theBorders
API to wrap nodes with zero or more Border implementations.class
A fluent API that is only indirectly instantiable via theBorders
fluent API, and which allows for anempty border
to be wrapped around a given Node.class
A fluent API that is only indirectly instantiable via theBorders
fluent API, and which allows for anetched border
to be wrapped around a given Node.class
A fluent API that is only indirectly instantiable via theBorders
fluent API, and which allows for aline border
to be wrapped around a given Node. -
Method Summary
Modifier and TypeMethodDescriptionaddBorder
(Borders.Border border) Allows for developers to develop customBorders.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.Often times it is useful to have a bit of whitespace around a Node, to separate it from what it is next to.The etched border look is essentially equivalent to thelineBorder()
look, except rather than one line, there are two.Creates a nice, simple border around the node.static Borders
wrap
(javafx.scene.Node n) Fluent API entry method(s)
-
Method Details
-
wrap
Fluent API entry method(s) -
emptyBorder
Often times it is useful to have a bit of whitespace around a Node, to separate it from what it is next to. Call this method to begin building a border that will wrap the node with a given amount of whitespace (which can vary between the top, right, bottom, and left sides). -
etchedBorder
The etched border look is essentially equivalent to thelineBorder()
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 inBorders.EtchedBorders
for more information. -
lineBorder
Creates a nice, simple border around the node. Note that there are many configuration options inBorders.LineBorders
, so explore it carefully. -
addBorder
Allows for developers to develop customBorders.Border
implementations, and to wrap them around a Node. Note that of course this is mostly redundant (as you could just callBorders.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. -
build
public javafx.scene.Node build()Returns the original node wrapped in zero or more borders, as specified using the fluent API.
-