I have a collection of buttons:
VBox menuButtons = new VBox();
menuButtons.getChildren().addAll(addButton, editButton, exitButton);
I want to add some spacing between this buttons, without using a CSS sheet. I think there should be a way for this.
setPadding(); is for the Buttons in the Box. setMargin(); should be for the Box itself. But I didn't find a way for the spacing between the buttons.
I'm glad for any ideas. :)
As others have mentioned you can use
setSpacing()
.However, you can also use
setMargin()
, it is not for the pane (or box in your words), it is for individualNode
s.setPadding()
method is for the pane itself. In fact,setMargin()
takes a node as a parameter so you can guess what it's for.For example:
You could get the same result if you replaced that line with
If you have several nodes that should be spaced,
setSpacing()
method is far more convenient because you need to callsetMargin()
for each individual node and that would be ridiculous. However,setMargin()
is what you need if you need margins(duh) around a node that you can determine how much to each side becausesetSpacing()
methods places spaces only in between nodes, not between the node and the edges of the window.Just call
setSpacing
method and pass some value. Example withHBox
(it's same forVBox
):And this is how it looks:
Without of spacing:
With spacing:
VBox
supports spacing:or
If you're using FXML, use the
spacing
attribute: