How to create a “spacer” in JavaFX (with a Region)

As a brief note to self, I just created a “spacer” in JavaFX using a Region, as shown in this code:

// a spacer to push the visible elements up a little
val spacer = new Region
VBox.setVgrow(spacer, Priority.ALWAYS)

I originally created the spacer as a Separator, which is the wrong thing (it’s more like an HTML <hr> tag). A JavaFX Region just gives you a blank space, which you can control as needed.

In my case the setVgrow part of this solution isn’t needed, but I’m keeping it here as a reminder of how to do that. As the code implies, I add this spacer to a VBox later in my code.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.