Spec-Zone .ru
спецификации, руководства, описания, API

JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

expand all

Profile: desktop, common

Overview

Encapsulates the state required for a node to be dynamically resized by its parent during the layout pass of the scene graph. A javafx.scene.Node subclass should mixin this class if it has a flexible range of acceptable sizes.

A Resizable has functions to express its acceptable size range to its parent:

In addition to having a range of acceptable sizes, a Resizable node also has functions to express its natural grow, shrink, and fill preferences:

These preferences will vary across the different Container and Control classes, so consult individual class documentation for defaults.

The size of a Resizable node is intended to be controlled by its parent and so applications should not explicitly set the width or height variables directly, as these will be overridden by the parent during layout.

The default resizing policy of all javafx.scene.Parent types (javafx.scene.Group, javafx.scene.CustomNode, Container) is to "auto-size" their managed children, which means each Resizable child will be resized to its preferred size. However, subclasses of javafx.scene.CustomNode and Container typically override their doLayout functions to resize children according to their own policies. The concrete Container classes will typically honor a Resizable's size, grow, shrink, and fill preferences; see individual class documentation for details on their policies: HBox, VBox, Flow, Stack, Tile.

If an application needs to explicitly control both the size and position of a Resizable node (instead of having its parent set its size and position during the layout pass) then it should unmanage the node (see "managed" variable on javafx.scene.Node).

Creating Resizable Classes

If a Resizable is created by mixing in this class directly rather than extending a Node class which is already Resizable (Container or javafx.scene.control.Control) then the subclass must include some boiler plate code to ensure it hooks in properly to the scene graph's layout mechanism:


 public class MyResizable extends CustomNode, Resizable {
     // if extending Parent class (CustomNode), ensure layout is requested
     // when size is altered
     override var width on replace { requestLayout(); }
     override var height on replace { requestLayout(); }

     // ensure layoutBounds tracks current width/height
     override var layoutBounds = bind BoundingBox {
         minX: 0 
         minY: 0
         width: this.width
         height: this.height
     }
 }
 
All Resizable subclasses (even those that extend Container or Control classes) must override getPrefWidth and getPrefHeight functions to return appropriate values:

 public class MyContainer extends Container {

     override function getPrefWidth(height:Number):Number {
         // compute preferred width based on own content/state
         // may query preferred widths of children during computation
     }
     override function getPrefHeight(width:Number):Number {
         // compute preferred height based on won content/state
         // may query preferred heights of children during computation
     }
 }
 
Failure to override these functions will typically result in the Resizable not being sized properly by its parent.

Profile: common

Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
publicheightNumber

The Resizable's layout height, which is set by the it's parent during layout and should not be set directly by the application.

The Resizable's layout height, which is set by the it's parent during layout and should not be set directly by the application. Any value set by the application will be overridden by the parent when it lays out the Resizable in accordance with the Resizable's sizing preferences and the parent's layout policy.

If an application needs to control the height of a Resizable node, it should override its preferred height using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { height: 100 }
      }
 

Profile: common

 
publicwidthNumber

The Resizable's layout width, which is set by the it's parent during layout and should not be set directly by the application.

The Resizable's layout width, which is set by the it's parent during layout and should not be set directly by the application. Any value set by the application will be overridden by the parent when it lays out the Resizable in accordance with the Resizable's sizing preferences and the parent's layout policy.

If an application needs to control the width of a Resizable node, it should override its preferred width using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { width: 100 }
      }
 

Profile: common

 

Inherited Variables

Function Summary

public getHFill() : Boolean

Returns the Resizable's horizontal fill preference, which indicates whether or not the Resizable's width should be resized beyond its preferred width (up to its maximum) to fill it's allocated layout area.

Returns the Resizable's horizontal fill preference, which indicates whether or not the Resizable's width should be resized beyond its preferred width (up to its maximum) to fill it's allocated layout area.

All container classes (HBox, VBox, Stack, Flow(vertical), Tile) consult this preference when resizing Resizable children.

An application may override the horizontal fill of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { hfill: true }
      }
 

This function returns false by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Boolean
 
public getHGrow() : javafx.scene.layout.Priority

Returns the Resizable's horizontal grow priority which determines whether it's layout area is given more horizontal space if its available.

Returns the Resizable's horizontal grow priority which determines whether it's layout area is given more horizontal space if its available.

The horizontal grow priority is only used if the parent container is resized larger than its preferred width and multiple nodes are competing for extra horizontal space, which for the concrete containers is only applicable to HBox. Note that growing applies only to the layout area assigned to the Resizable; how the Resizable is sized with respect to that area is determined separately by its size and fill preferences (see getPrefWidth and getPrefHFill).

If ALWAYS, the Resizable's layout area will always grow horizontally if there is additional space, sharing the increase with other nodes that have an hgrow of ALWAYS. The Resizable's layout area will never be grown beyond the Resizable's maximum width.

If SOMETIMES, the Resizable's layout area will only grow horizontally if either no other node has specified ALWAYS, or the additional space was not completely allocated to nodes specifying ALWAYS because of their maximum size limits.

If NEVER, the Resizable's layout area will never be grown horizontally if there is additional space.

If the Resizable returns ALWAYS or SOMETIMES, then getHFill should typically return true to ensure the node will be resized beyond its preferred to take advantage of its larger layout area.

An application may override the horizontal grow priority of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { hgrow: Priority.ALWAYS }
      }
 

This function returns Priority.NEVER by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Priority
 
public getHShrink() : javafx.scene.layout.Priority

Returns the Resizable's horizontal shrink priority, which determines whether it's layout area is given less horizontal space if its parent is resized smaller than its preferred width.

Returns the Resizable's horizontal shrink priority, which determines whether it's layout area is given less horizontal space if its parent is resized smaller than its preferred width.

The horizontal shrink priority is only used if the parent container is resized smaller than its preferred width and multiple nodes are competing for horizontal space, which for the concrete containers is only applicable to HBox.

If ALWAYS, the Resizable's layout area will always shrink horizontally if there is less space, sharing the decrease with other nodes that have an hshrink of ALWAYS. The Resizable's layout area will never be sized smaller than the node's minimum width.

If SOMETIMES, the Resizable's layout area will only shrink horizontally if either no other node has specified ALWAYS, or the reduced space was not completely distributed to nodes specifying ALWAYS because of their minimum size limits.

If NEVER, the Resizable's layout area will never be shrunken horizontally if there is reduced space.

An application may override the horizontal shrink priority of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { hshrink: Priority.ALWAYS }
      }
 

This function returns Priority.NEVER by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Priority
 
public getMaxHeight() : Number

Returns the Resizable's maximum height.

Returns the Resizable's maximum height. Layout containers should strive not to set the Resizable's height larger than this value. This value is computed by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the maximum height of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { maxHeight: 30 }
      }
 

This function returns Integer.MAX_VALUE by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Number

Profile: common

 
public getMaxWidth() : Number

Returns the Resizable's maximum width.

Returns the Resizable's maximum width. Layout containers should strive not to set the Resizable's width larger than this value. This value is computed by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the maximum width of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { maxWidth: 30 }
      }
 

This function returns Integer.MAX_VALUE by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Number

Profile: common

 
public getMinHeight() : Number

Returns the Resizable's minimum height.

Returns the Resizable's minimum height. Layout containers should strive not to set the Resizable's height smaller than this value. This value is computed by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the minimum height of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { minHeight: 30 }
      }
 

This function returns 0 by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Number

Profile: common

 
public getMinWidth() : Number

Returns the Resizable's minimum width.

Returns the Resizable's minimum width. Layout containers should strive not to set the Resizable's width smaller than this value. This value is calculated by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the minimum width of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { minWidth: 50 }
      }
 

This function returns 0 by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Number

Profile: common

 
public abstract getPrefHeight(width: Number) : Number

Returns the Resizable's preferred height, given the specified width.

Returns the Resizable's preferred height, given the specified width. If a particular width need not be factored into the result, -1 may be passed in as the width parameter. Implementations of this function may also choose to ignore width if it does not impact the result.

Layout containers should set the Resizable's height to this value whenever possible. This value is computed by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the preferred height of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { height: 80 }
      }
 

Resizable subclasses must override this function to return an appropriate value.

Parameters
width
Returns
Number

Profile: common

 
public abstract getPrefWidth(height: Number) : Number

Returns the Resizable's preferred width, given the specified height.

Returns the Resizable's preferred width, given the specified height. If a particular height need not be factored into the result, -1 may be passed in as the height parameter. Implementations of this function may also choose to ignore height if it does not impact the result.

Layout containers should set the Resizable's width to this value whenever possible. This value is computed by the node subclass using applicable state and variable settings and is not directly settable by applications.

An application may override the preferred width of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { width: 50 }
      }
 

Resizable subclasses must override this function to return an appropriate value.

Parameters
height
Returns
Number

Profile: common

 
public getVFill() : Boolean

Returns the Resizable's vertical fill preference, which indicates whether or not the Resizable's height should be resized beyond its preferred height (up to its maximum) to fill it's allocated layout area.

Returns the Resizable's vertical fill preference, which indicates whether or not the Resizable's height should be resized beyond its preferred height (up to its maximum) to fill it's allocated layout area.

All container classes (HBox, VBox, Stack, Flow(horizontal), Tile) consult this preference when resizing Resizable children.

An application may override the vertical fill of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { vfill: true }
      }
 

This function returns false by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Boolean
 
public getVGrow() : javafx.scene.layout.Priority

Returns the Resizable's vertical grow priority, which determines whether it's layout area is given more vertical space if its available.

Returns the Resizable's vertical grow priority, which determines whether it's layout area is given more vertical space if its available.

The vertical grow priority is only used if the parent container is resized larger than its preferred height and multiple nodes are competing for extra vertical space, which for the concrete containers is only applicable to VBox. Note that growing applies only to the layout area assigned to the Resizable; how the Resizable is sized with respect to that area is determined separately by its size and fill preferences (see getPrefHeight and getPrefVFill).

If ALWAYS, the Resizable's layout area will always grow vertically if there is additional space, sharing the increase with other nodes that have an vgrow of ALWAYS. The Resizable's layout area will never be grown beyond the Resizable's maximum height.

If SOMETIMES, the Resizable's layout area will only grow vertically if either no other node has specified ALWAYS, or the additional space was not completely allocated to nodes specifying ALWAYS because of their maximum size limits.

If NEVER, the Resizable's layout area will never be grown vertically if there is additional space.

If the Resizable returns ALWAYS or SOMETIMES, then getVFill should typically return true to ensure the node will be resized beyond its preferred to take advantage of its larger layout area.

An application may override the vertical grow priority of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { vgrow: Priority.ALWAYS }
      }
 

This function returns Priority.NEVER by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Priority
 
public getVShrink() : javafx.scene.layout.Priority

Returns the Resizable's vertical shrink priority, which determines whether it's layout area is given less vertical space if its parent is resized smaller than its preferred height.

Returns the Resizable's vertical shrink priority, which determines whether it's layout area is given less vertical space if its parent is resized smaller than its preferred height.

The vertical shrink priority is only used if the parent container is resized smaller than its preferred height and multiple nodes are competing for vertical space, which for the concrete containers is only applicable to VBox.

If ALWAYS, the Resizable's layout area will always shrink vertically if there is less space, sharing the decrease with other nodes that have an vshrink of ALWAYS. The Resizable's layout area will never be sized smaller than the node's minimum height.

If SOMETIMES, the Resizable's layout area will only shrink vertically if either no other node has specified ALWAYS, or the reduced space was not completely distributed to nodes specifying ALWAYS because of their minimum size limits.

If NEVER, the Resizable's layout area will never be shrunken vertically if there is reduced space.

An application may override the vertical shrink priority of a Resizable node using LayoutInfo:


      Label {
          layoutInfo: LayoutInfo { vshrink: Priority.ALWAYS }
      }
 

This function returns Priority.NEVER by default; Resizable subclasses should override this function to return an appropriate value.

Returns
Priority
 

Inherited Functions