- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.layout.Pane
-
- javafx.scene.layout.AnchorPane
-
- All Implemented Interfaces:
-
Styleable
,EventTarget
public class AnchorPane extends Pane
AnchorPane允许子节点的边缘锚定到锚定窗格边缘的偏移。 如果锚定窗格具有边框和/或填充集合,则偏移量将从这些插值的内边缘测量。无论孩子的可见财产价值如何,AnchorPane都会安排每个被管理的孩子; 所有布局计算都忽略非托管孩子。
AnchorPanes可能使用CSS来设计背景和边框。 有关详细信息,请参阅
Region
超类。锚定约束
该应用程序为每个小孩设置锚点约束,以在一侧或多侧配置锚点。 如果一个孩子被固定在相对侧(并且可调整大小)上,则锚点窗格将调整其大小以保持两个偏移量,否则锚点窗格将调整为其首选大小。 如果在前一种情况下(锚定在对面),并且小孩不能调整大小,那么只有顶部/左侧的锚点才能被履行。 AnchorPane提供静态方法来设置每个锚约束。
AnchorPane Constraint Table Constraint Type Description topAnchor double distance from the anchor pane's top insets to the child's top edge. leftAnchor double distance from the anchor pane's left insets to the child's left edge. bottomAnchor double distance from the anchor pane's bottom insets to the child's bottom edge. rightAnchor double distance from the anchor pane's right insets to the child's right edge.AnchorPane示例:
AnchorPane anchorPane = new AnchorPane(); // List should stretch as anchorPane is resized ListView list = new ListView(); AnchorPane.setTopAnchor(list, 10.0); AnchorPane.setLeftAnchor(list, 10.0); AnchorPane.setRightAnchor(list, 65.0); // Button will float on right edge Button button = new Button("Add"); AnchorPane.setTopAnchor(button, 10.0); AnchorPane.setRightAnchor(button, 10.0); anchorPane.getChildren().addAll(list, button);
可调整范围
锚定窗格的父级将在布局期间在锚定窗格的可调整大小范围内调整锚定窗格的大小。 默认情况下,锚窗格根据其内容计算该范围,如下表所示。
AnchorPane Resize Table width height minimum left/right insets plus width required to display children anchored at left/right with at least their min widths top/bottom insets plus height required to display children anchored at top/bottom with at least their min heights preferred left/right insets plus width required to display children anchored at left/right with at least their pref widths top/bottom insets plus height required to display children anchored at top/bottom with at least their pref heights maximum Double.MAX_VALUE Double.MAX_VALUE锚定窗格的无界最大宽度和高度是对父级的指示,可以将其调整大小超出其首选大小,以填充分配给它的任何空间。
AnchorPane提供了直接设置尺寸范围的属性。 这些属性默认为哨兵值Region.USE_COMPUTED_SIZE,但是应用程序可能会根据需要将它们设置为其他值:
anchorPane.setPrefSize(300, 300);
AnchorPane默认情况下不剪切其内容,因此如果锚定窗格的大小小于其首选大小,则儿童边界可能会延伸到其自己的边界之外。
- 从以下版本开始:
- JavaFX 2.0
-
-
Property Summary
-
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Properties inherited from class javafx.scene.Parent
needsLayout
-
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
-
-
Field Summary
-
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
-
-
构造方法摘要
构造方法 Constructor 描述 AnchorPane()
创建AnchorPane布局。AnchorPane(Node... children)
与给定的孩子创建AnchorPane布局。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 static void
clearConstraints(Node child)
从子节点中删除所有锚窗格约束。protected double
computeMinHeight(double width)
计算该区域的最小高度。protected double
computeMinWidth(double height)
计算该区域的最小宽度。protected double
computePrefHeight(double width)
计算给定宽度的该区域的首选高度; 区域子类应该覆盖此方法,以根据其内容和布局策略返回适当的值。protected double
computePrefWidth(double height)
计算给定高度的该区域的首选宽度。static Double
getBottomAnchor(Node child)
如果设置,返回小孩的底部锚约束。static Double
getLeftAnchor(Node child)
如果设置,返回小孩的左锚约束。static Double
getRightAnchor(Node child)
如果设置,返回小孩的右侧锚点约束。static Double
getTopAnchor(Node child)
如果设置,返回小孩的顶部锚约束。protected void
layoutChildren()
在布局传递过程中调用这个Parent
的孩子。static void
setBottomAnchor(Node child, Double value)
设置锚定窗格包含的小孩的底部锚点。static void
setLeftAnchor(Node child, Double value)
设置锚定窗格所包含的小孩的左侧锚点。static void
setRightAnchor(Node child, Double value)
为锚定窗格包含的小孩设置正确的锚点。static void
setTopAnchor(Node child, Double value)
设置锚定窗格包含的小孩的顶部锚点。-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from class javafx.scene.layout.Pane
getChildren
-
Methods inherited from class javafx.scene.Parent
getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
-
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, getBackground, getBorder, getClassCssMetaData, getCssMetaData, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
-
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
-
-
-
构造方法详细信息
-
AnchorPane
public AnchorPane()
创建AnchorPane布局。
-
AnchorPane
public AnchorPane(Node... children)
与给定的孩子创建AnchorPane布局。- 参数
-
children
- 此窗格的初始子项集。 - 从以下版本开始:
- JavaFX 8.0
-
-
方法详细信息
-
setTopAnchor
public static void setTopAnchor(Node child, Double value)
设置锚定窗格包含的小孩的顶部锚点。 如果设置了,锚定窗格将保持小孩的大小和位置,使其顶部始终被锚定窗格的顶部内容边缘偏移。 将值设置为null将删除约束。- 参数
-
child
- 锚点窗格的子节点 -
value
- 从锚定窗格顶部的偏移量
-
getTopAnchor
public static Double getTopAnchor(Node child)
如果设置,返回小孩的顶部锚约束。- 参数
-
child
- 锚点窗格的子节点 - 结果
- 从锚定窗格顶部的偏移量,如果没有设置顶部锚点,则为null
-
setLeftAnchor
public static void setLeftAnchor(Node child, Double value)
设置锚定窗格所包含的小孩的左侧锚点。 如果设置,锚定窗格将保持小孩的大小和位置,使其左侧始终从锚点窗格的左侧内容边缘偏移量。 将值设置为null将删除约束。- 参数
-
child
- 锚点窗格的子节点 -
value
- 锚定窗格左侧的偏移量
-
getLeftAnchor
public static Double getLeftAnchor(Node child)
如果设置,返回小孩的左锚约束。- 参数
-
child
- 锚点窗格的子节点 - 结果
- 从锚定窗格左侧的偏移量,如果未设置左侧锚点,则为null
-
setBottomAnchor
public static void setBottomAnchor(Node child, Double value)
设置锚定窗格包含的小孩的底部锚点。 如果设置,锚定窗格将保持小孩的大小和位置,使其底部总是从锚定窗格的底部内容边缘偏移该量。 将值设置为null将删除约束。- 参数
-
child
- 锚点窗格的子节点 -
value
- 从锚定窗格底部的偏移量
-
getBottomAnchor
public static Double getBottomAnchor(Node child)
如果设置,返回小孩的底部锚约束。- 参数
-
child
- 锚点窗格的子节点 - 结果
- 从锚定窗格底部的偏移量,如果没有设置底部锚点,则为null
-
setRightAnchor
public static void setRightAnchor(Node child, Double value)
为锚定窗格包含的小孩设置正确的锚点。 如果设置,锚窗格将保持小孩的大小和位置,使其正确始终从锚点窗格的正确内容边缘偏移量。 将值设置为null将删除约束。- 参数
-
child
- 锚点窗格的子节点 -
value
- 锚定窗格右侧的偏移量
-
getRightAnchor
public static Double getRightAnchor(Node child)
如果设置,返回小孩的右侧锚点约束。- 参数
-
child
- 锚点窗格的子节点 - 结果
- 从锚定窗格右侧的偏移量,如果没有设置右侧锚点,则为null
-
clearConstraints
public static void clearConstraints(Node child)
从子节点中删除所有锚窗格约束。- 参数
-
child
- 子节点
-
computeMinWidth
protected double computeMinWidth(double height)
描述从类复制:Region
计算该区域的最小宽度。 默认情况下返回左和右插入的总和。 区域子类应该覆盖此方法,以根据其内容和布局策略返回适当的值。 如果子类没有VERTICAL内容偏差,则可以忽略height参数。- 重写:
-
computeMinWidth
在Region
- 参数
-
height
- 如果最小宽度取决于应该使用的高度 - 结果
- 计算出该区域的最小宽度
-
computeMinHeight
protected double computeMinHeight(double width)
描述从类复制:Region
计算该区域的最小高度。 默认返回顶部和底部插入的总和。 区域子类应该覆盖此方法,以根据其内容和布局策略返回适当的值。 如果子类没有HORIZONTAL内容偏差,则可以忽略width参数。- 重写:
-
computeMinHeight
在Region
- 参数
-
width
- 如果最小高度取决于应该使用的宽度 - 结果
- 计算该区域的最小高度
-
computePrefWidth
protected double computePrefWidth(double height)
描述从类复制:Region
计算给定高度的该区域的首选宽度。 区域子类应该覆盖此方法,以根据其内容和布局策略返回适当的值。 如果子类没有VERTICAL内容偏差,则可以忽略height参数。- 重写:
-
computePrefWidth
在Region
- 参数
-
height
- 如果首选宽度取决于应该使用的高度 - 结果
- 计算这个区域的首选宽度
-
computePrefHeight
protected double computePrefHeight(double width)
描述从类别复制:Region
计算给定宽度的该区域的首选高度; 区域子类应该覆盖此方法,以根据其内容和布局策略返回适当的值。 如果子类没有HORIZONTAL内容偏差,则可以忽略width参数。- 重写:
-
computePrefHeight
在Region
- 参数
-
width
- 如果偏好的高度取决于应该使用的宽度 - 结果
- 该区域计算的优选高度
-
layoutChildren
protected void layoutChildren()
描述从类复制:Parent
在布局传递过程中调用这个Parent
的孩子。 默认情况下,它只会将受管理的可调整大小的内容的大小设置为其首选大小,并且不会执行任何节点定位。子类应该根据需要重写此函数以布局内容。
- 重写:
-
layoutChildren
在Parent
-
-