JavaFX: How to define margin to TextField in css?


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:

        <Insets bottom="10.0" left="60.0" right="0.0" top="10.0"/>

after each textfield is not a good solution for me.

10/23/2014 2:40:22 PM

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.

5/23/2017 12:17:58 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow