Question

I was used to Swing and I'm now beginning with FX. I came across a question which I couldn't find a answer reading the "Working With Layouts in JavaFX " Guide from Oracle and also doing some research on the internet.

In the FX API Guide for the GridPane Class there is an example about laying out the Objects:

here an excerpt from http://docs.oracle.com/javafx/2/api/javafx/scene/layout/GridPane.html : GridPane gridpane = new GridPane();

 // Set one constraint at a time...
 Button button = new Button();
 GridPane.setRowIndex(button, 1);
 GridPane.setColumnIndex(button, 2);

...

 // don't forget to add children to gridpane
 gridpane.getChildren().addAll(button, label);

The row and column information is set via static methods of GridPane. This is also what the documentation says. I'd like to understand where this Layout Constraints are bound to the Node Object - in this case the button.

The Node API doc does not mention the layout constraints. I found a lot information about setting Constraints eg for columns on a GridPane object, but I could not find about further information about this.

So how is the row/column information bound to the button or how can I retrieve this information from the button after it was applied ?

best regrads guenter

Was it helpful?

Solution

Reading through the javaFX source code, GridPane's setRowIndex and setColumnIndex use the setConstraint method of it's superclass Pane, which looks like this:

static void setConstraint(Node node, Object key, Object value) {
        if (value == null) {
            node.getProperties().remove(key);
        } else {
            node.getProperties().put(key, value);
        }
        if (node.getParent() != null) {
            node.getParent().requestLayout();
        }
    }

So the information gets stored directly in the node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top