Is <children> tag useful in fxml? Should it be removed?
Asked Answered
S

1

6

IntelliJ checkstyle indicates that this tag should be removed, as it is not required, as in instead of

<VBox>
  <children>
    <HBox>
        ...
    </HBox>
    <HBox>
        ...
    </HBox>
  </children>
</VBox>

you can simply have

<VBox>
  <HBox>
    ...
  </HBox>
  <HBox>
    ...
  </HBox>
</VBox>

This indeed helps not having bloated code at some times, but I failed to find a good reference on a convention here.

This link mentions that the tag is optional as "the loader will automatically add the sub-elements of the VBox to the container's "children" collection". But that doesn't make it very clear if it would be ok to adopt removing this tag from code or not as a convention?

Also, Scene Builder seems to add these tags to newly created controls, but it doesn't mind if you remove them. It does not re-add them while editing such a modified file.

Straightedge answered 28/7, 2017 at 15:28 Comment(0)
S
3

@DefaultProperty a property to which child elements will be added or set when an explicit property is not given. see this

Pane class and all it's subclasses have @DefaultProperty as children see this , so

Is children tag useful in fxml?

i think no , not really

Should it be removed?

it's depend on your preference

Suffuse answered 28/7, 2017 at 16:17 Comment(1)
I don't understand how the discussion of @DefaultProperty and Pane are relevant to the question being asked. Can someone elaborate?Chairborne

© 2022 - 2024 — McMap. All rights reserved.