Class Borders

  • public final class Borders
    extends Object
    A utility class that allows you to wrap JavaFX 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:

    Screenshot of Borders.LineBorders

    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:

    Screenshot of Borders.EtchedBorders

    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:

    Screenshot of two Borders.LineBorders
     Node wrappedButton = Borders.wrap(button)

    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.

    • Method Detail

      • wrap

        public static Borders wrap​(Node n)
        Fluent API entry method(s)
      • emptyBorder

        public 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. 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

        public Borders.EtchedBorders etchedBorder()
        The etched border look is essentially equivalent to the 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.
      • lineBorder

        public Borders.LineBorders lineBorder()
        Creates a nice, simple border around the node. Note that there are many configuration options in Borders.LineBorders, so explore it carefully.
      • addBorder

        public Borders addBorder​(Borders.Border border)
        Allows for developers to develop custom Borders.Border implementations, and to wrap them around a Node. Note that of course this is mostly redundant (as you could just call Borders.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 Node build()
        Returns the original node wrapped in zero or more borders, as specified using the fluent API.