Control基类及其继承者。是主要的与用户交互的UI组件。
一、接口篇。
Control实现了Skinnable接口,这个Skinnable接口就是可以用皮肤渲染组件的标志,实现它使组件可以自由地更换各种皮肤成为可能,这里只说是可能,因为还需要一个类Skin--皮肤的代表。可以这样理解诶一个Control组件就是一个Skinnable,然后需要Skin来提供渲染的皮肤。
Skinnable接口主要有以下方法:
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来提供皮肤外观。
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
InvalidationListener
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:
RadioButton, RadioMenuItem, ToggleButton
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.
|