Spec-Zone .ru
спецификации, руководства, описания, API
|
T
- This type is used to represent the type of the objects stored in
the ListViews items
ObservableList. It is
also used in the selection model
and focus model
.@DefaultProperty(value="items") public class ListView<T> extends Control
A simple example of how to create and populate a ListView of names (Strings) is shown here:
ObservableList<String> names = FXCollections.observableArrayList(
"Julia", "Ian", "Sue", "Matthew", "Hannah", "Stephan", "Denise");
ListView<String> listView = new ListView<String>(names);
The elements of the ListView are contained within the
items
ObservableList
. This
ObservableList is automatically observed by the ListView, such that any
changes that occur inside the ObservableList will be automatically shown in
the ListView itself. If passying the ObservableList
in to the
ListView constructor is not feasible, the recommended approach for setting
the items is to simply call:
ObservableList<T> content = ...
listView.setItems(content);
The end result of this is, as noted above, that the ListView will automatically
refresh the view to represent the items in the list.
Another approach, whilst accepted by the ListView, is not the recommended approach:
List<T> content = ...
getItems().setAll(content);
The issue with the approach shown above is that the content list is being
copied into the items list - meaning that subsequent changes to the content
list are not observed, and will not be reflected visually within the ListView.
To track selection and focus, it is necessary to become familiar with the
SelectionModel
and FocusModel
classes. A ListView has at most
one instance of each of these classes, available from
selectionModel
and
focusModel
properties respectively.
Whilst it is possible to use this API to set a new selection model, in
most circumstances this is not necessary - the default selection and focus
models should work in most circumstances.
The default SelectionModel
used when instantiating a ListView is
an implementation of the MultipleSelectionModel
abstract class.
However, as noted in the API documentation for
the selectionMode
property, the default value is SelectionMode.SINGLE
. To enable
multiple selection in a default ListView instance, it is therefore necessary
to do the following:
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
The visuals of the ListView can be entirely customized by replacing the
default cell factory
. A cell factory is used to
generate ListCell
instances, which are used to represent an item in the
ListView. See the Cell
class documentation for a more complete
description of how to write custom Cells.
ListCell
,
MultipleSelectionModel
,
FocusModel
Type | Property and Description |
---|---|
ObjectProperty<Callback<ListView<T>,ListCell<T>>> |
cellFactory
Setting a custom cell factory has the effect of deferring all cell
creation, allowing for total customization of the cell.
|
BooleanProperty |
editable
Specifies whether this ListView is editable - only if the ListView and
the ListCells within it are both editable will a ListCell be able to go
into their editing state.
|
ReadOnlyIntegerProperty |
editingIndex
A property used to represent the index of the item currently being edited
in the ListView, if editing is taking place, or -1 if no item is being edited.
|
ObjectProperty<FocusModel<T>> |
focusModel
The FocusModel provides the API through which it is possible
to both get and set the focus on a single item within a ListView.
|
ObjectProperty<ObservableList<T>> |
items
The underlying data model for the ListView.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditCancel
This event handler will be fired when the user cancels editing a cell.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditCommit
This property is used when the user performs an action that should
result in their editing input being persisted.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditStart
This event handler will be fired when the user successfully initiates
editing.
|
ObjectProperty<Orientation> |
orientation
The orientation of the
ListView - this can either be horizontal
or vertical. |
ObjectProperty<MultipleSelectionModel<T>> |
selectionModel
The SelectionModel provides the API through which it is possible
to select single or multiple items within a ListView, as well as inspect
which items have been selected by the user.
|
contextMenu, height, maxHeight, maxWidth, minHeight, minWidth, prefHeight, prefWidth, skinClassName, skin, tooltip, width
needsLayout
blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, visible
Modifier and Type | Class and Description |
---|---|
static class |
ListView.EditEvent<T>
An
Event subclass used specifically in ListView for representing
edit-related events. |
USE_COMPUTED_SIZE, USE_PREF_SIZE
Constructor and Description |
---|
ListView()
Creates a default ListView which will display contents stacked vertically.
|
ListView(ObservableList<T> items)
Creates a default ListView which will stack the contents retrieved from the
provided
ObservableList vertically. |
Modifier and Type | Method and Description |
---|---|
ObjectProperty<Callback<ListView<T>,ListCell<T>>> |
cellFactoryProperty()
Setting a custom cell factory has the effect of deferring all cell
creation, allowing for total customization of the cell.
|
void |
edit(int itemIndex)
Instructs the ListView to begin editing the item in the given index, if
the ListView is
editable . |
BooleanProperty |
editableProperty()
Specifies whether this ListView is editable - only if the ListView and
the ListCells within it are both editable will a ListCell be able to go
into their editing state.
|
static <T> EventType<ListView.EditEvent<T>> |
editAnyEvent()
An EventType that indicates some edit event has occurred.
|
static <T> EventType<ListView.EditEvent<T>> |
editCancelEvent()
An EventType used to indicate that an edit event has just been canceled
within the ListView upon which the event was fired.
|
static <T> EventType<ListView.EditEvent<T>> |
editCommitEvent()
An EventType used to indicate that an edit event has been committed
within the ListView upon which the event was fired.
|
ReadOnlyIntegerProperty |
editingIndexProperty()
A property used to represent the index of the item currently being edited
in the ListView, if editing is taking place, or -1 if no item is being edited.
|
static <T> EventType<ListView.EditEvent<T>> |
editStartEvent()
An EventType used to indicate that an edit event has started within the
ListView upon which the event was fired.
|
ObjectProperty<FocusModel<T>> |
focusModelProperty()
The FocusModel provides the API through which it is possible
to both get and set the focus on a single item within a ListView.
|
Callback<ListView<T>,ListCell<T>> |
getCellFactory()
Returns the current cell factory.
|
int |
getEditingIndex()
Returns the index of the item currently being edited in the ListView,
or -1 if no item is being edited.
|
FocusModel<T> |
getFocusModel()
Returns the currently installed
FocusModel . |
ObservableList<T> |
getItems()
Returns an
ObservableList that contains the items currently being
shown to the user. |
EventHandler<ListView.EditEvent<T>> |
getOnEditCancel()
Returns the
EventHandler that will be called when the user cancels
an edit. |
EventHandler<ListView.EditEvent<T>> |
getOnEditCommit()
Returns the
EventHandler that will be called when the user commits
an edit. |
EventHandler<ListView.EditEvent<T>> |
getOnEditStart()
Returns the
EventHandler that will be called when the user begins
an edit. |
Orientation |
getOrientation()
Returns the current orientation of the ListView, which dictates whether
it scrolls vertically or horizontally.
|
MultipleSelectionModel<T> |
getSelectionModel()
Returns the currently installed selection model.
|
boolean |
isEditable()
Gets the value of the property editable.
|
ObjectProperty<ObservableList<T>> |
itemsProperty()
The underlying data model for the ListView.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditCancelProperty()
This event handler will be fired when the user cancels editing a cell.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditCommitProperty()
This property is used when the user performs an action that should
result in their editing input being persisted.
|
ObjectProperty<EventHandler<ListView.EditEvent<T>>> |
onEditStartProperty()
This event handler will be fired when the user successfully initiates
editing.
|
ObjectProperty<Orientation> |
orientationProperty()
The orientation of the
ListView - this can either be horizontal
or vertical. |
void |
scrollTo(int index)
Scrolls the ListView such that the item in the given index is visible to
the end user.
|
ObjectProperty<MultipleSelectionModel<T>> |
selectionModelProperty()
The SelectionModel provides the API through which it is possible
to select single or multiple items within a ListView, as well as inspect
which items have been selected by the user.
|
void |
setCellFactory(Callback<ListView<T>,ListCell<T>> value)
Sets a new cell factory to use in the ListView.
|
void |
setEditable(boolean value)
Sets the value of the property editable.
|
void |
setFocusModel(FocusModel<T> value)
Sets the
FocusModel to be used in the ListView. |
void |
setItems(ObservableList<T> value)
Sets the underlying data model for the ListView.
|
void |
setOnEditCancel(EventHandler<ListView.EditEvent<T>> value)
Sets the
EventHandler that will be called when the user cancels
an edit. |
void |
setOnEditCommit(EventHandler<ListView.EditEvent<T>> value)
Sets the
EventHandler that will be called when the user has
completed their editing. |
void |
setOnEditStart(EventHandler<ListView.EditEvent<T>> value)
Sets the
EventHandler that will be called when the user begins
an edit. |
void |
setOrientation(Orientation value)
Sets the orientation of the ListView, which dictates whether
it scrolls vertically or horizontally.
|
void |
setSelectionModel(MultipleSelectionModel<T> value)
Sets the
MultipleSelectionModel to be used in the ListView. |
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getHeight, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getPrefHeight, getPrefWidth, getSkin, getTooltip, getUserAgentStylesheet, getWidth, heightProperty, intersects, isResizable, layoutChildren, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, setContextMenu, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setPrefHeight, setPrefSize, setPrefWidth, setSkin, setSkinClassName, setTooltip, setWidth, skinClassNameProperty, skinProperty, tooltipProperty, widthProperty
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, setNeedsLayout
addEventFilter, addEventHandler, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getUserData, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToSceneTransformProperty, lookupAll, managedProperty, mouseTransparentProperty, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, visibleProperty
public final ObjectProperty<ObservableList<T>> itemsProperty
getItems()
,
setItems(ObservableList)
public final ObjectProperty<MultipleSelectionModel<T>> selectionModelProperty
public final ObjectProperty<FocusModel<T>> focusModelProperty
getFocusModel()
,
setFocusModel(FocusModel)
public final ObjectProperty<Orientation> orientationProperty
ListView
- this can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final ObjectProperty<Callback<ListView<T>,ListCell<T>>> cellFactoryProperty
Setting a custom cell factory has the effect of deferring all cell creation, allowing for total customization of the cell. Internally, the ListView is responsible for reusing ListCells - all that is necessary is for the custom cell factory to return from this function a ListCell which might be usable for representing any item in the ListView.
Refer to the Cell
class documentation for more detail.
getCellFactory()
,
setCellFactory(Callback)
public final BooleanProperty editableProperty
isEditable()
,
setEditable(boolean)
public final ReadOnlyIntegerProperty editingIndexProperty
A property used to represent the index of the item currently being edited in the ListView, if editing is taking place, or -1 if no item is being edited.
It is not possible to set the editing index, instead it is required that
you call edit(int)
.
getEditingIndex()
public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditStartProperty
getOnEditStart()
,
setOnEditStart(EventHandler)
public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditCommitProperty
This property is used when the user performs an action that should result in their editing input being persisted.
The EventHandler in this property should not be called directly -
instead call ListCell.commitEdit(java.lang.Object)
from within
your custom ListCell. This will handle firing this event, updating the
view, and switching out of the editing state.
public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditCancelProperty
public ListView()
ObservableList
is provided in this constructor, an empty
ObservableList is created, meaning that it is legal to directly call
getItems()
if so desired. However, as noted elsewhere, this
is not the recommended approach
(instead call setItems(javafx.collections.ObservableList)
).
Refer to the ListView
class documentation for details on the
default state of other properties.
public ListView(ObservableList<T> items)
ObservableList
vertically.
Attempts to add a listener to the ObservableList
, such that all
subsequent changes inside the list will be shown to the user.
Refer to the ListView
class documentation for details on the
default state of other properties.
public static <T> EventType<ListView.EditEvent<T>> editAnyEvent()
EDIT_START_EVENT
,
EDIT_COMMIT_EVENT
and EDIT_CANCEL_EVENT
.public static <T> EventType<ListView.EditEvent<T>> editStartEvent()
public static <T> EventType<ListView.EditEvent<T>> editCancelEvent()
public static <T> EventType<ListView.EditEvent<T>> editCommitEvent()
public final void setItems(ObservableList<T> value)
public final ObservableList<T> getItems()
ObservableList
that contains the items currently being
shown to the user. This may be null if
setItems(javafx.collections.ObservableList)
has previously been
called, however, by default it is an empty ObservableList.public final ObjectProperty<ObservableList<T>> itemsProperty()
getItems()
,
setItems(ObservableList)
public final void setSelectionModel(MultipleSelectionModel<T> value)
MultipleSelectionModel
to be used in the ListView.
Despite a ListView requiring a MultipleSelectionModel, it is possible
to configure it to only allow single selection (see
MultipleSelectionModel.setSelectionMode(javafx.scene.control.SelectionMode)
for more information).public final MultipleSelectionModel<T> getSelectionModel()
public final ObjectProperty<MultipleSelectionModel<T>> selectionModelProperty()
public final void setFocusModel(FocusModel<T> value)
FocusModel
to be used in the ListView.public final FocusModel<T> getFocusModel()
FocusModel
.public final ObjectProperty<FocusModel<T>> focusModelProperty()
getFocusModel()
,
setFocusModel(FocusModel)
public final void setOrientation(Orientation value)
public final Orientation getOrientation()
public final ObjectProperty<Orientation> orientationProperty()
ListView
- this can either be horizontal
or vertical.getOrientation()
,
setOrientation(Orientation)
public final void setCellFactory(Callback<ListView<T>,ListCell<T>> value)
ListCell
's to be thrown away, and new ListCell's created with
the new cell factory.public final Callback<ListView<T>,ListCell<T>> getCellFactory()
public final ObjectProperty<Callback<ListView<T>,ListCell<T>>> cellFactoryProperty()
Setting a custom cell factory has the effect of deferring all cell creation, allowing for total customization of the cell. Internally, the ListView is responsible for reusing ListCells - all that is necessary is for the custom cell factory to return from this function a ListCell which might be usable for representing any item in the ListView.
Refer to the Cell
class documentation for more detail.
getCellFactory()
,
setCellFactory(Callback)
public final void setEditable(boolean value)
public final boolean isEditable()
public final BooleanProperty editableProperty()
isEditable()
,
setEditable(boolean)
public final int getEditingIndex()
public final ReadOnlyIntegerProperty editingIndexProperty()
A property used to represent the index of the item currently being edited in the ListView, if editing is taking place, or -1 if no item is being edited.
It is not possible to set the editing index, instead it is required that
you call edit(int)
.
getEditingIndex()
public final void setOnEditStart(EventHandler<ListView.EditEvent<T>> value)
EventHandler
that will be called when the user begins
an edit.
This is a convenience method - the same result can be
achieved by calling
addEventHandler(ListView.EDIT_START_EVENT, eventHandler)
.
public final EventHandler<ListView.EditEvent<T>> getOnEditStart()
EventHandler
that will be called when the user begins
an edit.public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditStartProperty()
getOnEditStart()
,
setOnEditStart(EventHandler)
public final void setOnEditCommit(EventHandler<ListView.EditEvent<T>> value)
EventHandler
that will be called when the user has
completed their editing. This is called as part of the
ListCell.commitEdit(java.lang.Object)
method.
This is a convenience method - the same result can be
achieved by calling
addEventHandler(ListView.EDIT_START_EVENT, eventHandler)
.
public final EventHandler<ListView.EditEvent<T>> getOnEditCommit()
EventHandler
that will be called when the user commits
an edit.public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditCommitProperty()
This property is used when the user performs an action that should result in their editing input being persisted.
The EventHandler in this property should not be called directly -
instead call ListCell.commitEdit(java.lang.Object)
from within
your custom ListCell. This will handle firing this event, updating the
view, and switching out of the editing state.
public final void setOnEditCancel(EventHandler<ListView.EditEvent<T>> value)
EventHandler
that will be called when the user cancels
an edit.public final EventHandler<ListView.EditEvent<T>> getOnEditCancel()
EventHandler
that will be called when the user cancels
an edit.public final ObjectProperty<EventHandler<ListView.EditEvent<T>>> onEditCancelProperty()
public void edit(int itemIndex)
editable
. Once
this method is called, if the current cellFactoryProperty()
is
set up to support editing, the Cell will switch its visual state to enable
for user input to take place.itemIndex
- The index of the item in the ListView that should be
edited.public void scrollTo(int index)
index
- The index that should be made visible to the user, assuming
of course that it is greater than, or equal to 0, and less than the
size of the items list contained within the given ListView.Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. Use is subject to