Java Reference
In-Depth Information
Ta b l e 5 . 3
JavaFX Controls ( Continued )
Control
Purpose
ScrollBar
A control that allows the user to control scrolling.
ToggleButton
A control with a Boolean indicating whether it has been selected.
Custom Controls
TextBox is a control—that is, it extends javafx.scene.control.Control and
has a companion class that is a Skin, javafx.scene.control.Skin . The advan-
tage of controls is that the Skin, or display characteristics, are separated from the
actual control. The other main advantage is that controls implement full style
sheet support including the pseudo classes :hover, :pressed, and :focused . Creat-
ing a custom control is easy.
First, create the Control by extending javafx.scene.control.Control . Within
this control, you need to assign a Skin to the skin variable inherited from
javafx.scene.control.Control . Let's look at an example that creates a con-
trol for hypertext. HyperText is a Text -like object that displays text; when you
click it, some action is taken on a URL. This is similar to links in a Web page. If
the link has not been visited, the text is displayed in one color, and after it has
been visited, it is displayed in another color. Also, typically these links are
underlined. The beauty of using a Control is that all these appearance attributes
can be set using a style sheet.
The HyperText object extends Control and assigns a HyperTextSkin object to
its skin variable. This is detailed in Listing 5.29.
Listing 5.29
Custom Control
public class HyperText extends Control {
public var url :String;
public var content : String;
public var action : function(url:String):Void;
public var textOrigin: TextOrigin =
HyperTextSkin.defaultText.textOrigin;
public var textAlignment: TextAlignment =
HyperTextSkin.defaultText.textAlignment;
init {
skin = HyperTextSkin {};
}
}
 
 
Search WWH ::




Custom Search