Richard Bair richard.bair at
Fri Jan 25 10:26:44 PST 2013

Jasper is running into situations with Modena where the ability to set margins from CSS would be useful (otherwise he has to resort to some nasty hacks). We've always wanted margins support as it seemed generally useful, and now it looks like we have the need.

The idea is to add a "margin" property to Node, and allow it to be set from CSS via "-fx-margin", or "-fx-margin-top", "-fx-margin-right", "-fx-margin-bottom", "-fx-margin-left", the same as HTML CSS.

The decision to add another property to Node doesn't come lightly, as that additional runtime cost applies to all nodes. To mitigate the cost, I propose adding "margin" to the "misc properties", so that any node that doesn't use margin doesn't pay the cost (if that doesn't make sense, take a look at the code for The reason it makes sense to add it to Node is that all Nodes participate in layout, and the concept of a Margin is commonly used in all (most?) layout panes. How the margin is used in the layout container depends on the layout container -- a box-model implementation of LayoutPane might collapse margins, whereas other layout containers might not (I don't think any of ours do).

Right now the margin has to be specified via static methods on the various layout classes, which end up putting a value on the properties map of a Node. Instead these would end up just setting the margin directly. Note that there is a small difference in behavior -- currently if you call the BorderPane#setMargin and HBox#setMargin with different values, and plop the node from one layout container to the other, then you will get different margin values depending on which it is set on. By redirecting the setMargin calls to instead set the margin on the Node itself, calling it twice for different layout containers will end up "stomping" on the same variable.

However that is an extremely uncommon use case. If instead we left the setMargin methods on the layout containers alone, people would be confused that setting the margin didn't set the margin property on the node. Heck, those methods could just be deprecated (never liked 'em anyway).


More information about the openjfx-dev mailing list