The JavaFX User Interface Controls (UI Controls or just Controls) are
specialized Nodes in the JavaFX Scenegraph especially suited for reuse in
many different application contexts. They are designed to be highly
customizable visually by designers and developers. They are designed to work
well with layout systems. Examples of prominent controls include Button,
Label, ListView, and TextField.
Since Controls are Nodes in the scenegraph,
they can be freely mixed with Groups,
Images,
Media,
Text, and
basic geometric shapes. While
writing new UI Controls is not trivial, using and styling them
is very easy, especially to existing web developers.
The remainder of this document will describe the basic architecture of the JavaFX UI Control library, how to style existing controls, write custom skins, and how to use controls to build up more complicated user interfaces.
Controls follow the classic MVC design pattern. The Control is
the "model". It contains both the state and the functions which manipulate
that state. The Control class itself does not know how it is rendered or
what the user interaction is. These tasks are delegated to the
Skin ("view"), which may internally separate
out the view and controller functionality into separate classes, although
at present there is no public API for the "controller" aspect.
All Controls extend from the Control class, which is in turn a
Parent node, and which is a
Node. Every Control has a reference to a single Skin, which
is the view implementation for the Control. The Control delegates to the
Skin the responsibility of computing the min, max, and pref sizes of the
Control, the baseline offset, and hit testing (containment and
intersection). It is also the responsibility of the Skin, or a delegate of
the Skin, to implement and respond to all relevant key
events which occur on the Control when it contains the focus.
Control extends from Parent, and as such, is
not a leaf node. From the perspective of a developer or designer the Control
can be thought of as if it were a leaf node in many cases. For example, the
developer or designer can consider a Button as if it were a Rectangle or
other simple leaf node.
Since a Control is resizable, a Control will be auto-sized to its preferred size on each scenegraph pulse. Setting the width and height of the Control does not affect its preferred size. When used in a layout container, the layout constraints imposed upon the Control (or manually specified on the Control) will determine how it is positioned and sized.
The Skin of a Control can be changed at any time. Doing so will mark the Control as needing to be laid out since changing the Skin likely has changed the preferred size of the Control. If no Skin is specified at the time that the Control is created, then a default CSS-based skin will be provided for all of the built-in Controls.
Each Control may have an optional tooltip specified. The Tooltip is a Control which displays some (usually textual) information about the control to the user when the mouse hovers over the Control from some period of time. It can be styled from CSS the same as with other Controls.
focusTraversable is overridden in Control to be true by default,
whereas with Node it is false by default. Controls which should not be
focusable by default (such as Label) override this to be false.
The getMinWidth, getMinHeight, getPrefWidth, getPrefHeight, getMaxWidth, and getMaxHeight functions are delegated directly to the Skin. The baselineOffset method is delegated to the node of the skin. It is not recommended that subclasses alter these delegations.
There are two methods for customizing the look of a Control. The most difficult and yet most flexible approach is to write a new Skin for the Control which precisely implements the visuals which you desire for the Control. Consult the Skin documentation for more details.
The easiest and yet very powerful method for styling the built in Controls is by using CSS. Please note that in this release the following CSS description applies only to the default Skins provided for the built in Controls. Subsequent releases will make this generally available for any custom third party Controls which desire to take advantage of these CSS capabilities.
Each of the default Skins for the built in Controls is comprised of multiple individually styleable areas or regions. This is much like an HTML page which is made up of <div>'s and then styled from CSS. Each individual region may be drawn with backgrounds, borders, images, padding, margins, and so on. The JavaFX CSS support includes the ability to have multiple backgrounds and borders, and to derive colors. These capabilities make it extremely easy to alter the look of Controls in JavaFX from CSS.
The colors used for drawing the default Skins of the built in Controls are all derived from a base color, an accent color and a background color. Simply by modifying the base color for a Control you can alter the derived gradients and create Buttons or other Controls which visually fit in with the default Skins but visually stand out.
As with all other Nodes in the scenegraph, Controls can be styled by using an external stylesheet, or by specifying the style directly on the Control. Although for examples it is easier to express and understand by specifying the style directly on the Node, it is recommended to use an external stylesheet and use either the styleClass or id of the Control, just as you would use the "class" or id of an HTML element with HTML CSS.
Each UI Control specifies a styleClass which may be used to style controls from an external stylesheet. For example, the Button control is given the "button" CSS style class. The CSS style class names are hyphen-separated lower case as opposed to camel case, otherwise, they are exactly the same. For example, Button is "button", RadioButton is "radio-button", Tooltip is "tooltip" and so on.
The class documentation for each Control defines the default Skin regions which can be styled. For further information regarding the CSS capabilities provided with JavaFX, see the CSS Reference Guide.
| Modifier and Type | Interface and Description |
|---|---|
| public interface | |
| public interface | |
| public interface | Toggle
Represents a control that can be toggled between selected and non-selected states. |
| Modifier and Type | Class and Description |
|---|---|
| public class | Accordion
An accordion is a group of |
| public class | |
| public class | Button
A simple button control. |
| public class | |
| public abstract class | ButtonBase
Base class for button-like UI Controls, including Hyperlinks, Buttons, ToggleButtons, CheckBoxes, and RadioButtons. |
| public class | ButtonType
The ButtonType class is used as part of the JavaFX |
| public class | |
| public class | CheckBox
A tri-state selection Control typically skinned as a box with a checkmark or tick mark when checked. |
| public class | CheckBoxTreeItem<
The type of the value contained within the TreeItem T>TreeItem subclass that adds support for being in selected, unselected, and indeterminate states. |
| public class | CheckMenuItem
A |
| public class | ChoiceBox<
the type of the item contained within the ChoiceBox T>The ChoiceBox is used for presenting the user with a relatively small set of predefined choices from which they may choose. |
| public class | ChoiceDialog<
The type of the items to show to the user, and the type that is returned
via T>getResult() when the dialog is dismissed.A dialog that shows a list of choices to the user, from which they can pick one item at most. |
| public class | ColorPicker
ColorPicker control allows the user to select a color from either a standard palette of colors with a simple one click selection OR define their own custom color. |
| public class | ComboBox<
The type of the value that has been selected or otherwise entered
in to this ComboBox T>An implementation of the |
| public abstract class | ComboBoxBase<
The type of the value that has been selected or otherwise
entered in to this ComboBox. T>Abstract base class for ComboBox-like controls. |
| public abstract class | ConstrainedColumnResizeBase
Base class for a constrained column resize policy. |
| public class | ContextMenu
A popup control containing an ObservableList of menu items. |
| public abstract class | Control
Base class for all user interface controls. |
| pack-priv class | |
| public class | CustomMenuItem
A |
| public class | DateCell
DateCell is used by |
| public class | DatePicker
The DatePicker control allows the user to enter a date as text or to select a date from a calendar popup. |
| public class | Dialog<
The return type of the dialog, via the
R>result property.A Dialog in JavaFX wraps a |
| public class | DialogEvent
Event related to dialog showing/hiding actions. |
| public class | DialogPane
DialogPane should be considered to be the root node displayed within a
|
| public abstract class | |
| pack-priv abstract class | |
| pack-priv class | |
| public class | Hyperlink
An HTML like label which can be a graphic and/or text which responds to rollovers and clicks. |
| public class | IndexedCell<
The type of the item contained within the Cell. T>An implementation of |
| public class | IndexRange
Class representing a contiguous range of integral values. |
| public class | Label
Label is a non-editable text control. |
| public abstract class | |
| public class | |
| public class | ListView<
This type is used to represent the type of the objects stored in
the ListViews T>items ObservableList. It is
also used in the selection model
and focus model.A ListView displays a horizontal or vertical list of items from which the user may select, or with which the user may interact. |
| public class | Menu
A popup menu of actionable items which is displayed to the user only upon request. |
| public class | |
| public class | MenuButton
MenuButton is a button which, when clicked or pressed, will show a
|
| public class | |
| public abstract class | MultipleSelectionModel<
The type of the item contained in the control that can be selected. T>An abstract class that extends |
| pack-priv abstract class | MultipleSelectionModelBase<
The type of the underlying data model for the UI control. T>An abstract class that implements more of the abstract MultipleSelectionModel abstract class. |
| public class | Pagination
A Pagination control is used for navigation between pages of a single content, which has been divided into smaller parts. |
| public class | PasswordField
Text field that masks entered characters. |
| public class | PopupControl
An extension of PopupWindow that allows for CSS styling. |
| public class | ProgressBar
A specialization of the ProgressIndicator which is represented as a horizontal bar. |
| public class | ProgressIndicator
A circular control which is used for indicating progress, either infinite (aka indeterminate) or finite. |
| public class | RadioButton
RadioButtons create a series of items where only one item can be selected. |
| public class | RadioMenuItem
A RadioMenuItem is a |
| public abstract class | ResizeFeaturesBase<
the type of the objects contained within the control's items list S>A wrapper class for use by the column resize policies offered by
controls such as |
| public class | ScrollBar
Either a horizontal or vertical bar with increment and decrement buttons and a "thumb" with which the user can interact. |
| public class | ScrollPane
A Control that provides a scrolled, clipped viewport of its contents. |
| public class | ScrollToEvent<
the scroll-to event type T>Event related to |
| public abstract class | SelectionModel<
The type of the item contained in the control that can be selected. T>SelectionModel is an abstract class used by UI controls to provide a consistent API for maintaining selection. |
| public class | Separator
A horizontal or vertical separator line. |
| public class | SeparatorMenuItem
A |
| public abstract class | SingleSelectionModel<
The type of the item contained in the control that can be selected. T>A SelectionModel which enforces the requirement that only a single index be selected at any given time. |
| public abstract class | |
| public class | Slider
The Slider Control is used to display a continuous or discrete range of valid numeric choices and allows the user to interact with the control. |
| public class | |
| public class | Spinner<
The type of all values that can be iterated through in the Spinner.
Common types include Integer and String. T>A single line text field that lets the user select a number or an object value from an ordered sequence. |
| public abstract class | SpinnerValueFactory<
The type of the data this value factory deals with, which must
coincide with the type of the Spinner that the value factory is set on. T>The SpinnerValueFactory is the model behind the JavaFX
|
| public class | SplitMenuButton
The SplitMenuButton, like the |
| public class | SplitPane
A control that has two or more sides, each separated by a divider, which can be dragged by the user to give more space to one of the sides, resulting in the other side shrinking by an equal amount. |
| public class | |
| public class | |
| public class | TableColumn<
The type of the TableView generic type (i.e. S == TableView<S>) S, The type of the content in all cells in this TableColumn. T>A |
| public abstract class | TableColumnBase<
The type of the UI control (e.g. the type of the 'row'). S, The type of the content in all cells in this table column. T>Table-like controls (such as |
| public abstract class | TableFocusModel<
The type of the underlying data model for the UI control. T, The concrete subclass of TC extends TableColumnBaseTableColumnBase that is used by the
underlying UI control (e.g. TableColumn or TreeTableColumn.The abstract base class for FocusModel implementations that are used within
table-like controls (most notably |
| public class | TablePosition<
The type of the items contained within the TableView (i.e. the same
generic type as the S in TableView<S>). S, The type of the items contained within the TableColumn. T>This class is used to represent a single row/column/cell in a TableView. |
| public abstract class | TablePositionBase<
the type of the TableColumnBase TC extends TableColumnBaseThis class is used to represent a single row/column/cell in a table. |
| public class | TableRow<
The type of the item contained within the Cell. T>TableRow is an |
| public abstract class | TableSelectionModel<
The type of the underlying data model for the UI control. T>The abstract base class for MultipleSelectionModel implementations that are used within
table-like controls (most notably |
| pack-priv class | TableUtil
A package protected util class used by TableView and TreeTableView to reduce the level of code duplication. |
| public class | TableView<
The type of the objects contained within the TableView items list. S>The TableView control is designed to visualize an unlimited number of rows of data, broken out into columns. |
| public class | |
| public class | TextArea
Text input component that allows a user to enter multiple lines of plain text. |
| public class | TextField
Text input component that allows a user to enter a single line of unformatted text. |
| public class | TextFormatter<
The type of the value V>A Formatter describes a format of a
|
| public abstract class | TextInputControl
Abstract base class for text input controls. |
| public class | TextInputDialog
A dialog that shows a text input control to the user. |
| public class | TitledPane
A TitledPane is a panel with a title that can be opened and closed. |
| public class | ToggleButton
A |
| public class | ToggleGroup
A class which contains a reference to all |
| public class | ToolBar
A ToolBar is a control which displays items horizontally or vertically. |
| public class | Tooltip
Tooltips are common UI elements which are typically used for showing additional information about a Node in the scenegraph when the Node is hovered over by the mouse. |
| public class | |
| public class | |
| public class | TreeTableCell<
The type of the TreeTableView generic type S, The type of the item contained within the Cell. T>Represents a single row/column intersection in a |
| public class | TreeTableColumn<
The type of the TableView generic type (i.e. S == TableView<S>) S, The type of the content in all cells in this TableColumn. T>A |
| public class | TreeTablePosition<
The type of the S, TreeItem instances contained within the
TreeTableView.The type of the items contained within the TreeTableColumn. T>This class is used to represent a single row/column/cell in a TreeTableView. |
| public class | TreeTableRow<
The type of the item contained within the Cell. T>TreeTableRow is an |
| public class | TreeTableView<
The type of the TreeItem instances used in this TreeTableView. S>The TreeTableView control is designed to visualize an unlimited number of rows of data, broken out into columns. |
| pack-priv class | TreeUtil
A package protected util class used by TreeView and TreeTableView to reduce the level of code duplication. |
| public class |
| Modifier and Type | Enum and Description |
|---|---|
| public enum | ContentDisplay
The position to place the content within a Label. |
| public enum | OverrunStyle
Defines the behavior of a labeled Control when the space for rendering the text is smaller than the space needed to render the entire string. |
| public enum | SelectionMode
An enumeration used to specify how many items may be selected in a
|
| public enum | TreeSortMode
Specifies how the tree items in tree-like UI controls should be sorted. |