Control基类及其继承者。是主要的与用户交互的UI组件。java
1、接口篇。app
Control实现了Skinnable接口,这个Skinnable接口就是能够用皮肤渲染组件的标志,实现它使组件能够自由地更换各类皮肤成为可能,这里只说是可能,由于还须要一个类Skin--皮肤的表明。能够这样理解诶一个Control组件就是一个Skinnable,而后须要Skin来提供渲染的皮肤。ide
Skinnable接口主要有如下方法:this
Skin<?> |
getSkin() Returns the skin that renders this |
void |
setSkin(Skin<?> value) Sets the skin that will render this |
ObjectProperty<Skin<?>> |
skinProperty() Skin is responsible for rendering this |
Skin皮肤接口定义了如何获取皮肤的方法。皮肤Skin也须要用一个Node来提供皮肤外观。
code
public interface Skin<C extends >
void |
dispose() Called by a Skinnable when the Skin is replaced on the Skinnable.对象 |
Node |
getNode() Gets the Node which represents this Skin.继承 |
C |
getSkinnable() Gets the Skinnable to which this Skin is assigned. |
这个接口就是文本输入内容的表明。Interface representing a text input's content.Since it is an ObservableStringValue, you can also bind to, or observe the content.他是一个能够被观察的字符串文本值对象。你经过它能够绑定或者观察该文本内容的变化。
void |
delete(int start, int end, boolean notifyListeners) Removes a sequence of characters from the content. |
java.lang.String |
get(int start, int end) Retrieves a subset of the content. |
void |
insert(int index, java.lang.String text, boolean notifyListeners) Inserts a sequence of characters into the content. |
int |
length() Returns the number of characters represented by the content. |
它的父类有:
All Superinterfaces:
Observable, ObservableObjectValue<java.lang.String>, ObservableStringValue, ObservableValue<java.lang.String>
Observable:在javafx.beans中,An Observable
is an entity that wraps content and allows to observe the content for invalidations.An implementation of Observable
may support lazy evaluation, which means that the content is not immediately recomputed after changes, but lazily the next time it is requested(他并不在改变后立刻进行验算,只是在请求时才验算,这就是懒验真。)
void |
addListener(InvalidationListener listener) Adds an |
void |
removeListener(InvalidationListener listener) Removes the given listener from the list of listeners, that are notified whenever the value of the |
javafx.beans.value
An InvalidationListener
is notified whenever an ObservableValue
becomes invalid. It can be registered and unregistered with Observable.addListener(InvalidationListener)
respectively Observable.removeListener(InvalidationListener)
For an in-depth explanation of invalidation events and how they differ from change events, see the documentation of ObservableValue
.
The same instance of InvalidationListener
can be registered to listen to multiple ObservableValues
.
InvalidationListener主要用于监听ObservableValue(能够监听的值对象),它只是在值无效的时候被通知。
须要实现如下方法:
void |
invalidated(Observable observable) This method needs to be provided by an implementation of |
ObservableValue是Observable的子类。
通常状况相爱咱们无须直接实现这个类,而是经过继承它的子类来实现自定义附加功能
The value of the ObservableValue
can be requested with getValue()
.
咱们可使用ObservableValue来监听到两种Value Change Event,一个是Value Change,一个是Value invadidation.能够经过InvalidationListener和ChangeListener来进行监听。
因为继承了Observale接口故而,它支持懒验证模式。
An implementation of ObservableValue
may support lazy evaluation
Important note: attaching a ChangeListener
enforces eager computation even if the implementation of the ObservableValue
supports lazy evaluation.
虽然支持懒验证模式,可是若是你附加一个ChangeListener到这个上面,这会致使懒验证失效,由于它不得不在每次值改变时进行提交验算通知ChangeListener,而这会致使大量的无谓消耗,因此除非确实有很是迫切的必要,不然不要破坏这种懒验证模式。
void |
addListener(ChangeListener<? super T> listener) Adds a |
T |
getValue() Returns the current value of this |
void |
removeListener(ChangeListener<? super T> listener) Removes the given listener from the list of listeners, that are notified whenever the value of the |
javafx.beans.value
实现它要覆盖:
void |
changed(ObservableValue<? extends T> observable, T oldValue, T newValue) This method needs to be provided by an implementation of |
好了如今回到咱们的TextInputControl.Content
它实现了ObservableStringValue类,而这个类有
javafx.beans.value
All Superinterfaces:
Observable, ObservableObjectValue<java.lang.String>, ObservableValue<java.lang.String>
TextInputControl.Content
Interface representing a text input's content. Since it is an ObservableStringValue, you can also bind to, or observe the content.
这个表明了咱们的文本输入内容,可是它能够绑定文本内容,监听文本内容的变化和有效性。
void |
delete(int start, int end, boolean notifyListeners) Removes a sequence of characters from the content. |
java.lang.String |
get(int start, int end) Retrieves a subset of the content. |
void |
insert(int index, java.lang.String text, boolean notifyListeners) Inserts a sequence of characters into the content. |
int |
length() Returns the number of characters represented by the content. |
addListener,removeListener,getValue等方法均继承ObservableValue接口addListener, getValue, removeListener
下面咱们来说
Toggle开关接口:
javafx.scene.control
All Known Implementing Classes:
Represents a control that can be toggled between selected and non-selected states. In addition, a Toggle can be assigned a
, which manages all assigned Toggles such that only a single Toggle within the ToggleGroup
may be selected at any one time.ToggleGroup
Toggle表明着单选或者开关状态,它是RadioButton,RadioMenuItem,ToggleButton的实现接口。使用时须要注意与ToggleGroup一块儿使用,
这相似与Swing里面的RadioButton和RadioButtonGroup的关系,须要使用ToggleGroup来组成和管理一个单选组或开关组使之这个组里只能有一个组件状态能够改变。
ObservableMap<java.lang.Object,java.lang.Object> |
getProperties() Returns an observable map of properties on this toggle for use primarily by application developers. |
ToggleGroup |
getToggleGroup() Returns The |
java.lang.Object |
getUserData() Returns a previously set Object property, or null if no such property has been set using the |
boolean |
isSelected() Indicates whether this |
BooleanProperty |
selectedProperty() The selected state for this |
void |
setSelected(boolean selected) Sets this |
void |
setToggleGroup(ToggleGroup toggleGroup) Sets the |
void |
setUserData(java.lang.Object value) Convenience method for setting a single Object property that can be retrieved at a later date. |
ObjectProperty<ToggleGroup> |
toggleGroupProperty() The |
-----------------
ToggleGroup
Toggle |
getSelectedToggle() Gets the selected |
ObservableList<Toggle> |
getToggles() The list of toggles within the ToggleGroup. |
ReadOnlyObjectProperty<Toggle> |
selectedToggleProperty() The selected toggle. |
void |
selectToggle(Toggle value) Selects the toggle. |