Top Description Inners Fields Constructors Methods
javafx.scene.control

public abstract Class Control

extends Region
implements Skinnable
Class Inheritance
All Implemented Interfaces
javafx.scene.control.Skinnable
Known Direct Subclasses
javafx.scene.control.Labeled, javafx.scene.control.ListView, javafx.scene.control.MenuBar, javafx.scene.control.Pagination, javafx.scene.control.ProgressIndicator, javafx.scene.control.ScrollBar, javafx.scene.control.ScrollPane, javafx.scene.control.Separator, javafx.scene.control.Slider, javafx.scene.control.Spinner, javafx.scene.control.SplitPane, javafx.scene.control.TableView, javafx.scene.control.TabPane, javafx.scene.control.TextInputControl, javafx.scene.control.ToolBar, javafx.scene.control.TreeTableView, javafx.scene.control.TreeView, com.sun.javafx.scene.control.InputField, com.sun.javafx.scene.control.skin.FXVK, javafx.scene.control.Accordion, javafx.scene.control.ButtonBar, javafx.scene.control.ChoiceBox, javafx.scene.control.ComboBoxBase
Imports
java.lang.ref.WeakReference, java.lang.reflect.Constructor, .InvocationTargetException, java.util.ArrayList, .Collections, .List, com.sun.javafx.scene.control.ControlAcceleratorSupport, .ControlHelper, .Logging, javafx.application.Application, javafx.beans.property.ObjectProperty, .ObjectPropertyBase, .SimpleObjectProperty, .StringProperty, javafx.collections.ObservableList, javafx.css.CssParser, .CssMetaData, .StyleableObjectProperty, .StyleableStringProperty, .Styleable, .StyleableProperty, javafx.event.EventHandler, javafx.scene.AccessibleAction, .AccessibleAttribute, .Node, javafx.scene.input.ContextMenuEvent, javafx.scene.layout.Region, com.sun.javafx.application.PlatformImpl, com.sun.javafx.css.StyleManager, com.sun.javafx.scene.NodeHelper, javafx.css.converter.StringConverter, com.sun.javafx.logging.PlatformLogger, .PlatformLogger.Level

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<ContextMenu>
contextMenu

The ContextMenu to show for this control.

private static final EventHandler<ContextMenuEvent>
contextMenuHandler

Handles context menu requests by popping up the menu.

private String
currentSkinClassName

Keeps a reference to the name of the class currently acting as the skin.

private ObjectProperty<Skin<?>>
private SkinBase<?>
skinBase

A private reference directly to the SkinBase instance that is used as the Skin for this Control.

private StringProperty
private boolean
private List<CssMetaData<? extends Styleable, ?>>
private ObjectProperty<Tooltip>
Inherited from javafx.scene.layout.Region:
USE_COMPUTED_SIZEUSE_PREF_SIZE

Constructor Summary

AccessConstructor and Description
protected
Control()

Create a new Control.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

A double representing the maximum height of this control.
computeMaxHeight
(double
The width of the Control, in case this value might dictate the maximum height.
width
)

Overrides javafx.scene.layout.Region.computeMaxHeight.

Computes the maximum allowable height of the Control, based on the provided width.

protected double

Returns:

A double representing the maximum width of this control.
computeMaxWidth
(double
The height of the Control, in case this value might dictate the maximum width.
height
)

Overrides javafx.scene.layout.Region.computeMaxWidth.

Computes the maximum allowable width of the Control, based on the provided height.

protected double

Returns:

A double representing the minimum height of this control.
computeMinHeight
(final double
The width of the Control, in case this value might dictate the minimum height.
width
)

Overrides javafx.scene.layout.Region.computeMinHeight.

Computes the minimum allowable height of the Control, based on the provided width.

protected double

Returns:

A double representing the minimum width of this control.
computeMinWidth
(final double
The height of the Control, in case this value might dictate the minimum width.
height
)

Overrides javafx.scene.layout.Region.computeMinWidth.

Computes the minimum allowable width of the Control, based on the provided height.

protected double
computePrefHeight(double
the width that should be used if preferred height depends on it
width
)

Overrides javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy.

protected double
computePrefWidth(double
the height that should be used if preferred width depends on it
height
)

Overrides javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height.

public final ObjectProperty<ContextMenu>
protected Skin<?>

Returns:

new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
createDefaultSkin
()

Create a new instance of the default skin for this control.

private void
public void
executeAccessibleAction(AccessibleAction
the action to execute
action
,
Object...
optional list of parameters
parameters
)

Overrides javafx.scene.Node.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

public double
getBaselineOffset()

Overrides javafx.scene.Parent.getBaselineOffset.

Calculates the baseline offset based on the first managed child.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public final ContextMenu
pack-priv ObservableList<Node>
protected List<CssMetaData<? extends Styleable, ?>>

Returns:

the unmodifiable list of the control's CSS-styleable properties
getControlCssMetaData
()

Gets the unmodifiable list of the control's CSS-styleable properties.

public final List<CssMetaData<? extends Styleable, ?>>
getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.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.

protected Boolean

Returns:

the initial focus traversable state of this control
getInitialFocusTraversable
()

Overrides javafx.scene.Node.getInitialFocusTraversable.

Returns the initial focus traversable state of this control, for use by the JavaFX CSS engine to correctly set its initial value.

public final Skin<?>
private Node

Returns:

The Skin's node, or null.
getSkinNode
()

Gets the Skin's node, or returns null if there is no Skin.

public final Tooltip
public boolean

Returns:

whether this node can be resized by its parent during layout
isResizable
()

Overrides javafx.scene.layout.Region.isResizable.

Returns true since all Controls are resizable.

protected void
layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent.

private static Class<?>

Returns:

The class. Cannot return null
loadClass
(final String
The name of the class we want to load
className
,
final Object
An optional instance used to help find the class to load
instance
)

Utility for loading a class in a manner that will work with multiple class loaders, as is typically found in OSGI modular applications.

pack-priv static void
loadSkinClass(final Skinnable control, final String skinClassName)

public Object
queryAccessibleAttribute(AccessibleAttribute
the requested attribute
attribute
,
Object...
optional list of parameters
parameters
)

Overrides javafx.scene.Parent.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

public final void
public final void
public final void
pack-priv StringProperty
public final ObjectProperty<Skin<?>>

Returns:

the skin property for this control
skinProperty
()

Implements javafx.scene.control.Skinnable.skinProperty.

Skin is responsible for rendering this Control.

public final ObjectProperty<Tooltip>

Returns:

the tool tip for this control
tooltipProperty
()

The ToolTip for this control.

Inherited from javafx.scene.layout.Region:
backgroundPropertyborderPropertycacheShapePropertycenterShapePropertygetBackgroundgetBordergetHeightgetInsetsgetMaxHeightgetMaxWidthgetMinHeightgetMinWidthgetOpaqueInsetsgetPaddinggetPrefHeightgetPrefWidthgetShapegetUserAgentStylesheetgetWidthheightPropertyinsetsPropertyisCacheShapeisCenterShapeisScaleShapeisSnapToPixellayoutInArealayoutInArealayoutInArealayoutInAreamaxHeightmaxHeightPropertymaxWidthmaxWidthPropertyminHeightminHeightPropertyminWidthminWidthPropertyopaqueInsetsPropertypaddingPropertypositionInAreapositionInAreaprefHeightprefHeightPropertyprefWidthprefWidthPropertyresizescaleShapePropertysetBackgroundsetBordersetCacheShapesetCenterShapesetHeightsetMaxHeightsetMaxSizesetMaxWidthsetMinHeightsetMinSizesetMinWidthsetOpaqueInsetssetPaddingsetPrefHeightsetPrefSizesetPrefWidthsetScaleShapesetShapesetSnapToPixelsetWidthshapePropertysnappedBottomInsetsnappedLeftInsetsnappedRightInsetsnappedTopInsetsnapPositionsnapPositionXsnapPositionYsnapSizesnapSizeXsnapSizeYsnapSpacesnapSpaceXsnapSpaceYsnapToPixelPropertywidthProperty

Field Detail

contextMenuback to summary
private ObjectProperty<ContextMenu> contextMenu

The ContextMenu to show for this control.

contextMenuHandlerback to summary
private static final EventHandler<ContextMenuEvent> contextMenuHandler

Handles context menu requests by popping up the menu. Note that we use this pattern to remove some of the anonymous inner classes which we'd otherwise have to create. When lambda expressions are supported, we could do it that way instead (or use MethodHandles).

currentSkinClassNameback to summary
private String currentSkinClassName

Keeps a reference to the name of the class currently acting as the skin.

skinback to summary
private ObjectProperty<Skin<?>> skin
skinBaseback to summary
private SkinBase<?> skinBase

A private reference directly to the SkinBase instance that is used as the Skin for this Control. A Control's Skin doesn't have to be of type SkinBase, although 98% of the time or greater it probably will be. Because instanceof checks and reading a value from a property are not cheap (on interpreters on slower hardware or mobile devices) it pays to have a direct reference here to the skinBase. We simply need to check this variable -- if it is not null then we know the Skin is a SkinBase and this is a direct reference to it. If it is null then we know the skin is not a SkinBase and we need to call getSkin().

skinClassNameback to summary
private StringProperty skinClassName
skinCreationLockedback to summary
private boolean skinCreationLocked
styleablePropertiesback to summary
private List<CssMetaData<? extends Styleable, ?>> styleableProperties
tooltipback to summary
private ObjectProperty<Tooltip> tooltip

Constructor Detail

Controlback to summary
protected Control()

Create a new Control.

Method Detail

computeMaxHeightback to summary
protected double computeMaxHeight(double width)

Overrides javafx.scene.layout.Region.computeMaxHeight.

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.

Parameters
width:double

The width of the Control, in case this value might dictate the maximum height.

Returns:double

A double representing the maximum height of this control.

Annotations
@Override
computeMaxWidthback to summary
protected double computeMaxWidth(double height)

Overrides javafx.scene.layout.Region.computeMaxWidth.

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.

Parameters
height:double

The height of the Control, in case this value might dictate the maximum width.

Returns:double

A double representing the maximum width of this control.

Annotations
@Override
computeMinHeightback to summary
protected double computeMinHeight(final double width)

Overrides javafx.scene.layout.Region.computeMinHeight.

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.

Parameters
width:double

The width of the Control, in case this value might dictate the minimum height.

Returns:double

A double representing the minimum height of this control.

Annotations
@Override
computeMinWidthback to summary
protected double computeMinWidth(final double height)

Overrides javafx.scene.layout.Region.computeMinWidth.

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.

Parameters
height:double

The height of the Control, in case this value might dictate the minimum width.

Returns:double

A double representing the minimum width of this control.

Annotations
@Override
computePrefHeightback to summary
protected double computePrefHeight(double width)

Overrides javafx.scene.layout.Region.computePrefHeight.

Doc from javafx.scene.layout.Region.computePrefHeight.

Computes the preferred height of this region for the given width; Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a HORIZONTAL content bias, then the width parameter can be ignored.

Parameters
width:double

Doc from javafx.scene.Parent.computePrefHeight.

the width that should be used if preferred height depends on it

Returns:double

the computed preferred height for this region

Annotations
@Override
computePrefWidthback to summary
protected double computePrefWidth(double height)

Overrides javafx.scene.layout.Region.computePrefWidth.

Doc from javafx.scene.layout.Region.computePrefWidth.

Computes the preferred width of this region for the given height. Region subclasses should override this method to return an appropriate value based on their content and layout strategy. If the subclass doesn't have a VERTICAL content bias, then the height parameter can be ignored.

Parameters
height:double

Doc from javafx.scene.Parent.computePrefWidth.

the height that should be used if preferred width depends on it

Returns:double

the computed preferred width for this region

Annotations
@Override
contextMenuPropertyback to summary
public final ObjectProperty<ContextMenu> contextMenuProperty()
createDefaultSkinback to summary
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:Skin<?>

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
doProcessCSSback to summary
private void doProcessCSS()

Hides javafx.scene.Parent.doProcessCSS.

executeAccessibleActionback to summary
public void executeAccessibleAction(AccessibleAction action, Object... parameters)

Overrides javafx.scene.Node.executeAccessibleAction.

Doc from javafx.scene.Node.executeAccessibleAction.

This method is called by the assistive technology to request the action indicated by the argument should be executed.

This method is commonly overridden by subclasses to implement action that are required for a specific role.
If a particular action is not handled, the superclass implementation must be called.

Parameters
action:AccessibleAction

the action to execute

parameters:Object[]

optional list of parameters

Annotations
@Override
getBaselineOffsetback to summary
public double getBaselineOffset()

Overrides javafx.scene.Parent.getBaselineOffset.

Doc from javafx.scene.Parent.getBaselineOffset.

Calculates the baseline offset based on the first managed child. If there is no such child, returns Node#getBaselineOffset().

Returns:double

baseline offset

Annotations
@Override
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.layout.Region.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getContextMenuback to summary
public final ContextMenu getContextMenu()
getControlChildrenback to summary
pack-priv ObservableList<Node> getControlChildren()
getControlCssMetaDataback to summary
protected List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Gets the unmodifiable list of the control's CSS-styleable properties.

Returns:List<CssMetaData<? extends Styleable, ?>>

the unmodifiable list of the control's CSS-styleable properties

Since
JavaFX 8.0
getCssMetaDataback to summary
public final List<CssMetaData<? extends Styleable, ?>> getCssMetaData()

Overrides javafx.scene.layout.Region.getCssMetaData.

Implements javafx.css.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 Control#getControlCssMetaData() or SkinBase#getCssMetaData(), depending on where the CssMetaData resides.

Returns:List<CssMetaData<? extends Styleable, ?>>

Doc from javafx.scene.Node.getCssMetaData.

The CssMetaData associated with this node, which may include the CssMetaData of its superclasses.

Annotations
@Override
Since
JavaFX 8.0
getInitialFocusTraversableback to summary
protected Boolean getInitialFocusTraversable()

Overrides javafx.scene.Node.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.

Returns:Boolean

the initial focus traversable state of this control

Annotations
@Override
Since
9
getSkinback to summary
public final Skin<?> getSkin()

Implements javafx.scene.control.Skinnable.getSkin.

Annotations
@Override
getSkinNodeback to summary
private Node getSkinNode()

Gets the Skin's node, or returns null if there is no Skin. Convenience method for getting the node of the skin. This is null-safe, meaning if skin is null then it will return null instead of throwing a NullPointerException.

Returns:Node

The Skin's node, or null.

getTooltipback to summary
public final Tooltip getTooltip()
isResizableback to summary
public boolean isResizable()

Overrides javafx.scene.layout.Region.isResizable.

Returns true since all Controls are resizable.

Returns:boolean

whether this node can be resized by its parent during layout

Annotations
@Override
layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.Parent.layoutChildren.

Doc from javafx.scene.Parent.layoutChildren.

Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

Subclasses should override this function to layout content as needed.

Annotations
@Override
loadClassback to summary
private static Class<?> loadClass(final String className, final Object instance) throws ClassNotFoundException

Utility for loading a class in a manner that will work with multiple class loaders, as is typically found in OSGI modular applications. In particular, this method will attempt to just load the class identified by className. If that fails, it attempts to load the class using the current thread's context class loader. If that fails, it attempts to use the class loader of the supplied "instance", and if it still fails it walks up the class hierarchy of the instance and attempts to use the class loader of each class in the super-type hierarchy.

Parameters
className:String

The name of the class we want to load

instance:Object

An optional instance used to help find the class to load

Returns:Class<?>

The class. Cannot return null

Exceptions
ClassNotFoundException:
If the class cannot be found using any technique.
loadSkinClassback to summary
pack-priv static void loadSkinClass(final Skinnable control, final String skinClassName)
queryAccessibleAttributeback to summary
public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.Parent.queryAccessibleAttribute.

Doc from javafx.scene.Parent.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Parameters
attribute:AccessibleAttribute

Doc from javafx.scene.Node.queryAccessibleAttribute.

the requested attribute

parameters:Object[]

Doc from javafx.scene.Node.queryAccessibleAttribute.

optional list of parameters

Returns:Object

Doc from javafx.scene.Node.queryAccessibleAttribute.

the value for the requested attribute

Annotations
@Override
setContextMenuback to summary
public final void setContextMenu(ContextMenu value)
setSkinback to summary
public final void setSkin(Skin<?> value)

Implements javafx.scene.control.Skinnable.setSkin.

Annotations
@Override
setTooltipback to summary
public final void setTooltip(Tooltip value)
skinClassNamePropertyback to summary
pack-priv StringProperty skinClassNameProperty()
skinPropertyback to summary
public final ObjectProperty<Skin<?>> skinProperty()

Implements javafx.scene.control.Skinnable.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.

To ensure a one-to-one relationship between a Control and its Skin, skins which were not created for this control are rejected with an IllegalArgumentException. Then, Skin#dispose() is called on the old skin, disconnecting it from the corresponding Control. And finally, Skin#install() is invoked to complete the process. Only inside of Skin#install() should Skin implementations set/overwrite properties of their Control (though some operations like adding/removing a listener can still be done in the Skin constructor).

A skin may be null.

Returns:ObjectProperty<Skin<?>>

the skin property for this control

Annotations
@Override
Exceptions
IllegalArgumentException:
if (skin != null && skin.getSkinnable() != this)
tooltipPropertyback to summary
public final ObjectProperty<Tooltip> tooltipProperty()

The ToolTip for this control.

Returns:ObjectProperty<Tooltip>

the tool tip for this control

javafx.scene.control back to summary

private Class Control.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<Control, String>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SKINback to summary
private static final CssMetaData<Control, String> SKIN
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()