5

I want to specify only one (or several) values for a padding using CSS in JavaFX.

I've read the documentation here http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typesize but I can either specify a value for all four side of padding, or a value for each one.

Is it not possible to specify, for example, my top padding and let the rest be inherited? Same goes for borders..

Maxoudela
  • 2,091
  • 3
  • 15
  • 23
  • Inheritance is passed from parent node to child. So say parent node has some padding values, it is not logical to have the same paddings for child. WDUT? – Uluk Biy May 26 '15 at 13:13
  • Well maybe not inherit but nothing maybe. Suppose I have a css class with top-padding set and another with left-padding set. I would want to set both style class on the same Node. This seems to be currently impossible because all values must be set – Maxoudela May 26 '15 at 13:30
  • Padding defines the space between component border and its content. **It does not make sense to have undefined values there - it is either 0 or some value.** – Eugene Ryzhikov May 26 '15 at 17:46
  • 2
    I want to have the same possibilities of the CSS (http://www.w3schools.com/css/css_padding.asp). If nothing is specified, default value is taken (0). But to be compelled to set a value prevent the possibility to define several CSS classes applied on a Node that will define all possible values when combined together.. – Maxoudela May 27 '15 at 08:15
  • 3
    Does this answer your question? [How to only change left padding in javafx css](https://stackoverflow.com/questions/38528328/how-to-only-change-left-padding-in-javafx-css) – tomorrow Oct 27 '21 at 20:37

2 Answers2

6

You will have to CSS like so yourObject.setStyle("-fx-padding: 10 0 0 0;"); This will add padding only on the top side of your object. In CSS, the padding parameters are entered in this order: TOP, RIGHT, BOTTOM, LEFT. Clockwise. So ie. if you wanted to add 30 padding to the left side of your object, you'd use this: yourObject.setStyle("-fx-padding: 0 0 0 30;"); You can also combine it anyway you want (top and right for example).

Mirza Suljić
  • 157
  • 2
  • 9
  • No this does not answer my question because in your example, you are specifying 4 padding value. What I want is to specify the left one and that's it. In your example for the left side, you are specifying 0 for top, 0 for right, 0 for bottom and 30 for left. – Maxoudela Feb 09 '16 at 13:17
  • Well, I don't think you can use inheriting in JavaFX, so in your case I think the best solution is to simply find the padding of the parent and set it like I've shown above. – Mirza Suljić Feb 11 '16 at 21:43
1

you can edit it easly with sceneBuilder

enter image description here

so if you want to edit the padding with your code java (in particular when you make an interanl class ) you can simply call the function setPadding(), ok!. But if you want to set the margin you have to do that throught the parent layout because it's not internal properties .. ==> [your element_parent_layout].setMargin([your element], new Insets([top],[right],[bottom],[left]));

sorry for this quick answer .., if you have any problem you can ask me ;)

Community
  • 1
  • 1
Smaillns
  • 2,540
  • 1
  • 28
  • 40