Class Control

All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
Accordion, ButtonBar, ChoiceBox, ComboBoxBase, HTMLEditor, Labeled, ListView, MenuBar, Pagination, ProgressIndicator, ScrollBar, ScrollPane, Separator, Slider, Spinner, SplitPane, TableView, TabPane, TextInputControl, ToolBar, TreeTableView, TreeView

public abstract class Control extends Region implements Skinnable
Base class for all user interface controls. A "Control" is a node in the scene graph which can be manipulated by the user. Controls provide additional variables and behaviors beyond those of Node to support common user interactions in a manner which is consistent and predictable for the user.

Additionally, controls support explicit skinning to make it easy to leverage the functionality of a control while customizing its appearance.

See specific Control subclasses for information on how to use individual types of controls.

Most controls have their focusTraversable property set to true by default, however read-only controls such as Label and ProgressIndicator, and some controls that are containers ScrollPane and ToolBar do not. Consult individual control documentation for details.

Since:
JavaFX 2.0
  • Property Details

  • Constructor Details

    • Control

      protected Control()
      Create a new Control.
  • Method Details

    • skinProperty

      public final ObjectProperty<Skin<?>> skinProperty()
      Skin is responsible for rendering this Control. From the perspective of the Control, the Skin is a black box. It listens and responds to changes in state in a Control.

      There is a one-to-one relationship between a Control and its Skin. Every Skin maintains a back reference to the Control via the Skin.getSkinnable() method.

      A skin may be null.

      Specified by:
      skinProperty in interface Skinnable
      Returns:
      the skin property for this control
      See Also:
    • setSkin

      public final void setSkin(Skin<?> value)
      Sets the value of the property skin.
      Specified by:
      setSkin in interface Skinnable
      Property description:
      Skin is responsible for rendering this Control. From the perspective of the Control, the Skin is a black box. It listens and responds to changes in state in a Control.

      There is a one-to-one relationship between a Control and its Skin. Every Skin maintains a back reference to the Control via the Skin.getSkinnable() method.

      A skin may be null.

      Parameters:
      value - the skin value for this control
    • getSkin

      public final Skin<?> getSkin()
      Gets the value of the property skin.
      Specified by:
      getSkin in interface Skinnable
      Property description:
      Skin is responsible for rendering this Control. From the perspective of the Control, the Skin is a black box. It listens and responds to changes in state in a Control.

      There is a one-to-one relationship between a Control and its Skin. Every Skin maintains a back reference to the Control via the Skin.getSkinnable() method.

      A skin may be null.

      Returns:
      the skin for this control
    • tooltipProperty

      public final ObjectProperty<Tooltip> tooltipProperty()
      The ToolTip for this control.
      See Also:
    • setTooltip

      public final void setTooltip(Tooltip value)
      Sets the value of the property tooltip.
      Property description:
      The ToolTip for this control.
    • getTooltip

      public final Tooltip getTooltip()
      Gets the value of the property tooltip.
      Property description:
      The ToolTip for this control.
    • contextMenuProperty

      public final ObjectProperty<ContextMenu> contextMenuProperty()
      The ContextMenu to show for this control.
      See Also:
    • setContextMenu

      public final void setContextMenu(ContextMenu value)
      Sets the value of the property contextMenu.
      Property description:
      The ContextMenu to show for this control.
    • getContextMenu

      public final ContextMenu getContextMenu()
      Gets the value of the property contextMenu.
      Property description:
      The ContextMenu to show for this control.
    • isResizable

      public boolean isResizable()
      Returns true since all Controls are resizable.
      Overrides:
      isResizable in class Region
      Returns:
      whether this node can be resized by its parent during layout
      See Also:
    • computeMinWidth

      protected double computeMinWidth(double height)
      Computes the minimum allowable width of the Control, based on the provided height. The minimum width is not calculated within the Control, instead the calculation is delegated to the Node.minWidth(double) method of the Skin. If the Skin is null, the returned value is 0.
      Overrides:
      computeMinWidth in class Region
      Parameters:
      height - The height of the Control, in case this value might dictate the minimum width.
      Returns:
      A double representing the minimum width of this control.
    • computeMinHeight

      protected double computeMinHeight(double width)
      Computes the minimum allowable height of the Control, based on the provided width. The minimum height is not calculated within the Control, instead the calculation is delegated to the Node.minHeight(double) method of the Skin. If the Skin is null, the returned value is 0.
      Overrides:
      computeMinHeight in class Region
      Parameters:
      width - The width of the Control, in case this value might dictate the minimum height.
      Returns:
      A double representing the minimum height of this control.
    • computeMaxWidth

      protected double computeMaxWidth(double height)
      Computes the maximum allowable width of the Control, based on the provided height. The maximum width is not calculated within the Control, instead the calculation is delegated to the Node.maxWidth(double) method of the Skin. If the Skin is null, the returned value is 0.
      Overrides:
      computeMaxWidth in class Region
      Parameters:
      height - The height of the Control, in case this value might dictate the maximum width.
      Returns:
      A double representing the maximum width of this control.
    • computeMaxHeight

      protected double computeMaxHeight(double width)
      Computes the maximum allowable height of the Control, based on the provided width. The maximum height is not calculated within the Control, instead the calculation is delegated to the Node.maxHeight(double) method of the Skin. If the Skin is null, the returned value is 0.
      Overrides:
      computeMaxHeight in class Region
      Parameters:
      width - The width of the Control, in case this value might dictate the maximum height.
      Returns:
      A double representing the maximum height of this control.
    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).
      Returns:
      new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
      Since:
      JavaFX 8.0
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getCssMetaData

      public final List<CssMetaData<? extends Styleable,?>> getCssMetaData()
      This method returns a List containing all CssMetaData for both this Control (returned from getControlCssMetaData() and its Skin, assuming the skin property is a SkinBase.

      Developers who wish to provide custom CssMetaData are therefore encouraged to override getControlCssMetaData() or SkinBase.getCssMetaData(), depending on where the CssMetaData resides.

      Specified by:
      getCssMetaData in interface Styleable
      Overrides:
      getCssMetaData in class Region
      Returns:
      The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.
      Since:
      JavaFX 8.0
    • getControlCssMetaData

      protected List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Gets the unmodifiable list of the control's CSS-styleable properties.
      Returns:
      the unmodifiable list of the control's CSS-styleable properties
      Since:
      JavaFX 8.0
    • getInitialFocusTraversable

      protected Boolean getInitialFocusTraversable()
      Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value. By default all UI controls are focus traversable, so this method is overridden in Control to set the initial traversable state to true.
      Overrides:
      getInitialFocusTraversable in class Node
      Returns:
      the initial focus traversable state of this control
      Since:
      9