39 import javafx.geometry.Insets;
40 import javafx.geometry.Orientation;
41 import javafx.geometry.Pos;
42 import javafx.geometry.VPos;
43 import javafx.scene.Node;
44 import javafx.css.converter.EnumConverter;
45 import javafx.css.converter.SizeConverter;
46 import javafx.css.Styleable;
47
48 import static javafx.geometry.Orientation.*;
49 import javafx.util.Callback;
50
51 /**
52 * FlowPane lays out its children in a flow that wraps at the flowpane's boundary.
53 * <p>
54 * A horizontal flowpane (the default) will layout nodes in rows, wrapping at the
55 * flowpane's width. A vertical flowpane lays out nodes in columns,
56 * wrapping at the flowpane's height. If the flowpane has a border and/or padding set,
57 * the content will be flowed within those insets.
58 * <p>
59 * FlowPane's prefWrapLength property establishes it's preferred width
60 * (for horizontal) or preferred height (for vertical). Applications should set
61 * prefWrapLength if the default value (400) doesn't suffice. Note that prefWrapLength
62 * is used only for calculating the preferred size and may not reflect the actual
63 * wrapping dimension, which tracks the actual size of the flowpane.
64 * <p>
65 * The alignment property controls how the rows and columns are aligned
66 * within the bounds of the flowpane and defaults to Pos.TOP_LEFT. It is also possible
67 * to control the alignment of nodes within the rows and columns by setting
68 * rowValignment for horizontal or columnHalignment for vertical.
69 * <p>
70 * Example of a horizontal flowpane:
71 * <pre>{@code
72 * Image images[] = { ... };
73 * FlowPane flow = new FlowPane();
74 * flow.setVgap(8);
75 * flow.setHgap(4);
76 * flow.setPrefWrapLength(300); // preferred width = 300
77 * for (int i = 0; i < images.length; i++) {
78 * flow.getChildren().add(new ImageView(image[i]);
79 * }
120 * <br>
121 * <table border="1">
122 * <caption>Vertical</caption>
123 * <tr><td></td><th scope="col">width</th><th scope="col">height</th></tr>
124 * <tr><th scope="row">minimum</th>
125 * <td>left/right insets plus width required to display all children at their preferred widths when wrapped at a specified height</td>
126 * <td>top/bottom insets plus largest of children's pref heights</td></tr>
127 * <tr><th scope="row">preferred</th>
128 * <td>left/right insets plus width required to display all children at their pref widths when wrapped at the specified height</td>
129 * <td>top/bottom insets plus prefWrapLength</td></tr>
130 * <tr><th scope="row">maximum</th>
131 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr>
132 * </table>
133 * <p>
134 * A flowpane's unbounded maximum width and height are an indication to the parent that
135 * it may be resized beyond its preferred size to fill whatever space is assigned to it.
136 * <p>
137 * FlowPane provides properties for setting the size range directly. These
138 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the
139 * application may set them to other values as needed:
140 * <pre>{@code
141 * <b>flowpane.setMaxWidth(500);</b>
142 * }</pre>
143 * Applications may restore the computed values by setting these properties back
144 * to Region.USE_COMPUTED_SIZE.
145 * <p>
146 * FlowPane does not clip its content by default, so it is possible that childrens'
147 * bounds may extend outside its own bounds if a child's pref size is larger than
148 * the space flowpane has to allocate for it.</p>
149 *
150 * @since JavaFX 2.0
151 */
152 public class FlowPane extends Pane {
153
154 /********************************************************************
155 * BEGIN static methods
156 ********************************************************************/
157 private static final String MARGIN_CONSTRAINT = "flowpane-margin";
158
159 /**
160 * Sets the margin for the child when contained by a flowpane.
161 * If set, the flowpane will layout it out with the margin space around it.
162 * Setting the value to null will remove the constraint.
163 * @param child the child node of a flowpane
164 * @param value the margin of space around the child
165 */
166 public static void setMargin(Node child, Insets value) {
|
39 import javafx.geometry.Insets;
40 import javafx.geometry.Orientation;
41 import javafx.geometry.Pos;
42 import javafx.geometry.VPos;
43 import javafx.scene.Node;
44 import javafx.css.converter.EnumConverter;
45 import javafx.css.converter.SizeConverter;
46 import javafx.css.Styleable;
47
48 import static javafx.geometry.Orientation.*;
49 import javafx.util.Callback;
50
51 /**
52 * FlowPane lays out its children in a flow that wraps at the flowpane's boundary.
53 * <p>
54 * A horizontal flowpane (the default) will layout nodes in rows, wrapping at the
55 * flowpane's width. A vertical flowpane lays out nodes in columns,
56 * wrapping at the flowpane's height. If the flowpane has a border and/or padding set,
57 * the content will be flowed within those insets.
58 * <p>
59 * FlowPane's prefWrapLength property establishes its preferred width
60 * (for horizontal) or preferred height (for vertical). Applications should set
61 * prefWrapLength if the default value (400) doesn't suffice. Note that prefWrapLength
62 * is used only for calculating the preferred size and may not reflect the actual
63 * wrapping dimension, which tracks the actual size of the flowpane.
64 * <p>
65 * The alignment property controls how the rows and columns are aligned
66 * within the bounds of the flowpane and defaults to Pos.TOP_LEFT. It is also possible
67 * to control the alignment of nodes within the rows and columns by setting
68 * rowValignment for horizontal or columnHalignment for vertical.
69 * <p>
70 * Example of a horizontal flowpane:
71 * <pre>{@code
72 * Image images[] = { ... };
73 * FlowPane flow = new FlowPane();
74 * flow.setVgap(8);
75 * flow.setHgap(4);
76 * flow.setPrefWrapLength(300); // preferred width = 300
77 * for (int i = 0; i < images.length; i++) {
78 * flow.getChildren().add(new ImageView(image[i]);
79 * }
120 * <br>
121 * <table border="1">
122 * <caption>Vertical</caption>
123 * <tr><td></td><th scope="col">width</th><th scope="col">height</th></tr>
124 * <tr><th scope="row">minimum</th>
125 * <td>left/right insets plus width required to display all children at their preferred widths when wrapped at a specified height</td>
126 * <td>top/bottom insets plus largest of children's pref heights</td></tr>
127 * <tr><th scope="row">preferred</th>
128 * <td>left/right insets plus width required to display all children at their pref widths when wrapped at the specified height</td>
129 * <td>top/bottom insets plus prefWrapLength</td></tr>
130 * <tr><th scope="row">maximum</th>
131 * <td>Double.MAX_VALUE</td><td>Double.MAX_VALUE</td></tr>
132 * </table>
133 * <p>
134 * A flowpane's unbounded maximum width and height are an indication to the parent that
135 * it may be resized beyond its preferred size to fill whatever space is assigned to it.
136 * <p>
137 * FlowPane provides properties for setting the size range directly. These
138 * properties default to the sentinel value Region.USE_COMPUTED_SIZE, however the
139 * application may set them to other values as needed:
140 * <pre><code>
141 * <b>flowPane.setMaxWidth(500);</b>
142 * </code></pre>
143 * Applications may restore the computed values by setting these properties back
144 * to Region.USE_COMPUTED_SIZE.
145 * <p>
146 * FlowPane does not clip its content by default, so it is possible that children's
147 * bounds may extend outside its own bounds if a child's pref size is larger than
148 * the space flowpane has to allocate for it.</p>
149 *
150 * @since JavaFX 2.0
151 */
152 public class FlowPane extends Pane {
153
154 /********************************************************************
155 * BEGIN static methods
156 ********************************************************************/
157 private static final String MARGIN_CONSTRAINT = "flowpane-margin";
158
159 /**
160 * Sets the margin for the child when contained by a flowpane.
161 * If set, the flowpane will layout it out with the margin space around it.
162 * Setting the value to null will remove the constraint.
163 * @param child the child node of a flowpane
164 * @param value the margin of space around the child
165 */
166 public static void setMargin(Node child, Insets value) {
|