Is it possible to define padding and margin for TextFields in JavaFX using CSS? I have tried -fx-padding and some other properties, but no effect.  I am using JavaFX 2.2 which is included in the latest version of Java 7.
I have many textfields and doing something like:
    <GridPane.margin>
        <Insets bottom="10.0" left="60.0" right="0.0" top="10.0"/>
    </GridPane.margin>
after each textfield is not a good solution for me.
Modified copy from Confgure margin for individual element via java fx css
Theres no -fx-margin:5px css property for javafx textfields, but you can workaround the behaviour with a combination of padding, border-insets and background-insets.
For example a text-field with a 5px margin.
.text-field-with-margin {
    -fx-padding: 5px;
    -fx-border-insets: 5px;
    -fx-background-insets: 5px;
}
Alternatively you can also define a higher padding and lower insets values in case you want a padding and a margin.
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