I've used html+css quite a lot but I'm completely new to javafx+css. So this will be a newbie question but I can't find the answer anywhere.
I have a large GridPane full of Labels (besides others). I can set padding for all these Labels like:
GridPane.containerLevel02 Label {
-fx-padding: 0 0 0 5;
}
This works. I want some of the labels to be more indented so I create the "leftIndent" class for them:
GridPane.containerLevel02 Label.leftIndent {
-fx-padding: 0 0 0 20;
}
This works too.
BUT, I don't want to specify the three zeros there because if I ever decide to add top/bottom padding to Labels in general, it will not affect the "leftIndent" labels.
What I'm looking for is something like:
GridPane.containerLevel02 Label.leftIndent {
-fx-padding-left: 20;
}
... like in "normal" CSS or ...
GridPane.containerLevel02 Label.leftIndent {
-fx-padding: null null null 20;
}
...or anything that would let me specify left padding leaving the top, right and bottom padding untouched with whatever values they currently have.
Is that possible? THANKS!
The padding-left CSS property sets the width of the padding area to the left of an element.
You can set the margin for child nodes of a JavaFX VBox using the static setMargin() method. Here is an example of setting the margin around a JavaFX Button using the setMargin() method: Button button = new Button("Button 1"); VBox vbox = new VBox(button); VBox. setMargin(button, new Insets(10, 10, 10, 10));
padding:10px 5px 15px 20px; top padding is 10px. right padding is 5px. bottom padding is 15px. left padding is 20px.
Since JavaFX does not provide a -fx-padding-left
or similar, I think your easiest workaround is to use variables. For instance:
.root {
LABEL_PADDING_TOP: 0;
LABEL_PADDING_RIGHT: 0;
LABEL_PADDING_BOTTOM: 0;
LABEL_PADDING_LEFT: 5;
}
GridPane.containerLevel02 Label {
-fx-padding: LABEL_PADDING_TOP LABEL_PADDING_RIGHT LABEL_PADDING_BOTTOM LABEL_PADDING_LEFT;
}
GridPane.containerLevel02 Label.leftIndent {
-fx-padding: LABEL_PADDING_TOP LABEL_PADDING_RIGHT LABEL_PADDING_BOTTOM 20;
}
It still requires you to override all values which can be unwanted in certain use cases, but at least you have to specify your defaults only at one place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With