< prev index next >

modules/javafx.graphics/src/main/java/javafx/scene/layout/GridPane.java

Print this page




 119  *     Label label = new Label();
 120  *     <b>GridPane.setConstraints(label, 2, 0);</b> // column=2 row=0
 121  *
 122  *     // don't forget to add children to gridpane
 123  *     <b>gridpane.getChildren().addAll(button, label);</b>
 124  * </code></pre>
 125  *
 126  * Applications may also use convenience methods which combine the steps of
 127  * setting the constraints and adding the children:
 128  * <pre><code>
 129  *     GridPane gridpane = new GridPane();
 130  *     <b>gridpane.add(new Button(), 1, 0);</b> // column=1 row=0
 131  *     <b>gridpane.add(new Label(), 2, 0);</b>  // column=2 row=0
 132  * </code></pre>
 133  *
 134  *
 135  * <h3>Row/Column Sizing</h3>
 136  *
 137  * By default, rows and columns will be sized to fit their content;
 138  * a column will be wide enough to accommodate the widest child, a
 139  * row tall enough to fit the tallest child.However, if an application needs
 140  * to explicitly control the size of rows or columns, it may do so by adding
 141  * RowConstraints and ColumnConstraints objects to specify those metrics.
 142  * For example, to create a grid with two fixed-width columns:
 143  * <pre><code>
 144  *     GridPane gridpane = new GridPane();
 145  *     <b>gridpane.getColumnConstraints().add(new ColumnConstraints(100));</b> // column 0 is 100 wide
 146  *     <b>gridpane.getColumnConstraints().add(new ColumnConstraints(200));</b> // column 1 is 200 wide
 147  * </code></pre>
 148  * By default the gridpane will resize rows/columns to their preferred sizes (either
 149  * computed from content or fixed), even if the gridpane is resized larger than
 150  * its preferred size.   If an application needs a particular row or column to
 151  * grow if there is extra space, it may set its grow priority on the RowConstraints
 152  * or ColumnConstraints object.  For example:
 153  * <pre><code>
 154  *     GridPane gridpane = new GridPane();
 155  *     ColumnConstraints column1 = new ColumnConstraints(100,100,Double.MAX_VALUE);
 156  *     <b>column1.setHgrow(Priority.ALWAYS);</b>
 157  *     ColumnConstraints column2 = new ColumnConstraints(100);
 158  *     gridpane.getColumnConstraints().addAll(column1, column2); // first column gets any extra width
 159  * </code></pre>


 945                         constraints.add(GridPane.this);
 946                     }
 947                 }
 948             }
 949             requestLayout();
 950         }
 951     };
 952 
 953     /**
 954      * Returns list of column constraints. Column constraints can be added to
 955      * explicitly control individual column sizing and layout behavior.
 956      * If not set, column sizing and layout behavior is computed based on content.
 957      *
 958      * Index in the ObservableList denotes the column number, so the column constraint for the first column
 959      * is at the position of 0.
 960      * @return the list of column constraints
 961      */
 962     public final ObservableList<ColumnConstraints> getColumnConstraints() { return columnConstraints; }
 963 
 964     /**
 965      * Adds a child to the gridpane at the specified column,row position.
 966      * This convenience method will set the gridpane column and row constraints
 967      * on the child.
 968      * @param child the node being added to the gridpane
 969      * @param columnIndex the column index position for the child within the gridpane, counting from 0
 970      * @param rowIndex the row index position for the child within the gridpane, counting from 0
 971      */
 972     public void add(Node child, int columnIndex, int rowIndex) {
 973         setConstraints(child, columnIndex, rowIndex);
 974         getChildren().add(child);
 975     }
 976 
 977     /**
 978      * Adds a child to the gridpane at the specified column,row position and spans.
 979      * This convenience method will set the gridpane column, row, and span constraints
 980      * on the child.
 981      * @param child the node being added to the gridpane
 982      * @param columnIndex the column index position for the child within the gridpane, counting from 0
 983      * @param rowIndex the row index position for the child within the gridpane, counting from 0
 984      * @param colspan the number of columns the child's layout area should span
 985      * @param rowspan the number of rows the child's layout area should span
 986      */
 987     public void add(Node child, int columnIndex, int rowIndex, int colspan, int rowspan) {
 988         setConstraints(child, columnIndex, rowIndex, colspan, rowspan);
 989         getChildren().add(child);
 990     }
 991 
 992     /**
 993      * Convenience method for placing the specified nodes sequentially in a given
 994      * row of the gridpane.    If the row already contains nodes the specified nodes
 995      * will be appended to the row.  For example, the first node will be positioned at [column,row],
 996      * the second at [column+1,row], etc.   This method will set the appropriate gridpane
 997      * row/column constraints on the nodes as well as add the nodes to the gridpane's
 998      * children sequence.




 119  *     Label label = new Label();
 120  *     <b>GridPane.setConstraints(label, 2, 0);</b> // column=2 row=0
 121  *
 122  *     // don't forget to add children to gridpane
 123  *     <b>gridpane.getChildren().addAll(button, label);</b>
 124  * </code></pre>
 125  *
 126  * Applications may also use convenience methods which combine the steps of
 127  * setting the constraints and adding the children:
 128  * <pre><code>
 129  *     GridPane gridpane = new GridPane();
 130  *     <b>gridpane.add(new Button(), 1, 0);</b> // column=1 row=0
 131  *     <b>gridpane.add(new Label(), 2, 0);</b>  // column=2 row=0
 132  * </code></pre>
 133  *
 134  *
 135  * <h3>Row/Column Sizing</h3>
 136  *
 137  * By default, rows and columns will be sized to fit their content;
 138  * a column will be wide enough to accommodate the widest child, a
 139  * row tall enough to fit the tallest child. However, if an application needs
 140  * to explicitly control the size of rows or columns, it may do so by adding
 141  * RowConstraints and ColumnConstraints objects to specify those metrics.
 142  * For example, to create a grid with two fixed-width columns:
 143  * <pre><code>
 144  *     GridPane gridpane = new GridPane();
 145  *     <b>gridpane.getColumnConstraints().add(new ColumnConstraints(100));</b> // column 0 is 100 wide
 146  *     <b>gridpane.getColumnConstraints().add(new ColumnConstraints(200));</b> // column 1 is 200 wide
 147  * </code></pre>
 148  * By default the gridpane will resize rows/columns to their preferred sizes (either
 149  * computed from content or fixed), even if the gridpane is resized larger than
 150  * its preferred size.   If an application needs a particular row or column to
 151  * grow if there is extra space, it may set its grow priority on the RowConstraints
 152  * or ColumnConstraints object.  For example:
 153  * <pre><code>
 154  *     GridPane gridpane = new GridPane();
 155  *     ColumnConstraints column1 = new ColumnConstraints(100,100,Double.MAX_VALUE);
 156  *     <b>column1.setHgrow(Priority.ALWAYS);</b>
 157  *     ColumnConstraints column2 = new ColumnConstraints(100);
 158  *     gridpane.getColumnConstraints().addAll(column1, column2); // first column gets any extra width
 159  * </code></pre>


 945                         constraints.add(GridPane.this);
 946                     }
 947                 }
 948             }
 949             requestLayout();
 950         }
 951     };
 952 
 953     /**
 954      * Returns list of column constraints. Column constraints can be added to
 955      * explicitly control individual column sizing and layout behavior.
 956      * If not set, column sizing and layout behavior is computed based on content.
 957      *
 958      * Index in the ObservableList denotes the column number, so the column constraint for the first column
 959      * is at the position of 0.
 960      * @return the list of column constraints
 961      */
 962     public final ObservableList<ColumnConstraints> getColumnConstraints() { return columnConstraints; }
 963 
 964     /**
 965      * Adds a child to the gridpane at the specified column and row position.
 966      * This convenience method will set the gridpane column and row constraints
 967      * on the child.
 968      * @param child the node being added to the gridpane
 969      * @param columnIndex the column index position for the child within the gridpane, counting from 0
 970      * @param rowIndex the row index position for the child within the gridpane, counting from 0
 971      */
 972     public void add(Node child, int columnIndex, int rowIndex) {
 973         setConstraints(child, columnIndex, rowIndex);
 974         getChildren().add(child);
 975     }
 976 
 977     /**
 978      * Adds a child to the gridpane at the specified column and row position and spans.
 979      * This convenience method will set the gridpane column, row, and span constraints
 980      * on the child.
 981      * @param child the node being added to the gridpane
 982      * @param columnIndex the column index position for the child within the gridpane, counting from 0
 983      * @param rowIndex the row index position for the child within the gridpane, counting from 0
 984      * @param colspan the number of columns the child's layout area should span
 985      * @param rowspan the number of rows the child's layout area should span
 986      */
 987     public void add(Node child, int columnIndex, int rowIndex, int colspan, int rowspan) {
 988         setConstraints(child, columnIndex, rowIndex, colspan, rowspan);
 989         getChildren().add(child);
 990     }
 991 
 992     /**
 993      * Convenience method for placing the specified nodes sequentially in a given
 994      * row of the gridpane.    If the row already contains nodes the specified nodes
 995      * will be appended to the row.  For example, the first node will be positioned at [column,row],
 996      * the second at [column+1,row], etc.   This method will set the appropriate gridpane
 997      * row/column constraints on the nodes as well as add the nodes to the gridpane's
 998      * children sequence.


< prev index next >