Class GridView<T>

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
org.controlsfx.control.GridView<T>
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable

public class GridView<T> extends javafx.scene.control.Control
A GridView is a virtualised control for displaying getItems() in a visual, scrollable, grid-like fashion. In other words, whereas a ListView shows one ListCell per row, in a GridView there will be zero or more GridCell instances on a single row.

This approach means that the number of GridCell instances instantiated will be a significantly smaller number than the number of items in the GridView items list, as only enough GridCells are created for the visible area of the GridView. This helps to improve performance and reduce memory consumption.

Because each GridCell extends from Cell, the same approach of cell factories that is taken in other UI controls is also taken in GridView. This has two main benefits:

  1. GridCells are created on demand and without user involvement,
  2. GridCells can be arbitrarily complex. A simple GridCell may just have its text property set, whereas a more complex GridCell can have an arbitrarily complex scenegraph set inside its graphic property (as it accepts any Node).

Examples

The following screenshot shows the GridView with the ColorGridCell being used:
Screenshot of GridView

To create this GridView was simple. Note that the majority of the code below is related to randomly creating the colours to be represented:

 
 GridView<Color> myGrid = new GridView<>(list);
 myGrid.setCellFactory(new Callback<GridView<Color>, GridCell<Color>>() {
     public GridCell<Color> call(GridView<Color> gridView) {
         return new ColorGridCell();
     }
 });
 Random r = new Random(System.currentTimeMillis());
 for(int i = 0; i < 500; i++) {
     list.add(new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), 1.0));
 }
 
See Also:
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.ObjectProperty<javafx.util.Callback<GridView<T>,GridCell<T>>>
    Property representing the cell factory that is currently set in this GridView, or null if no cell factory has been set (in which case the default cell factory provided by the GridView skin will be used).
    final javafx.beans.property.DoubleProperty
    Property representing the height that all cells should be.
    final javafx.beans.property.DoubleProperty
    Property representing the width that all cells should be.
    final javafx.beans.property.DoubleProperty
    Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).
    final javafx.beans.property.ObjectProperty<javafx.collections.ObservableList<T>>
    The items to be displayed in the GridView (as rendered via GridCell instances).
    final javafx.beans.property.DoubleProperty
    Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).

    Properties inherited from class javafx.scene.control.Control

    contextMenu, skin, tooltip

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, 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, viewOrder, visible
  • Field Summary

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default, empty GridView control.
    GridView(javafx.collections.ObservableList<T> items)
    Creates a default GridView control with the provided items prepopulated.
  • Method Summary

    Modifier and Type
    Method
    Description
    final javafx.beans.property.ObjectProperty<javafx.util.Callback<GridView<T>,GridCell<T>>>
    Property representing the cell factory that is currently set in this GridView, or null if no cell factory has been set (in which case the default cell factory provided by the GridView skin will be used).
    final javafx.beans.property.DoubleProperty
    Property representing the height that all cells should be.
    final javafx.beans.property.DoubleProperty
    Property representing the width that all cells should be.
    protected javafx.scene.control.Skin<?>
    final javafx.util.Callback<GridView<T>,GridCell<T>>
    Returns the cell factory that will be used to create GridCell instances to show in the GridView.
    final double
    Returns the height that all cells should be.
    final double
    Returns the width that all cells should be.
    static List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>>
     
    List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>>
    final double
    Returns the amount of horizontal spacing there is between cells in the same row.
    final javafx.collections.ObservableList<T>
    Returns the currently-in-use items list that is being used by the GridView.
    protected final String
    getUserAgentStylesheet(Class<?> clazz, String fileName)
    A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once.
    final double
    Returns the amount of vertical spacing there is between cells in the same column.
    final javafx.beans.property.DoubleProperty
    Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).
    final javafx.beans.property.ObjectProperty<javafx.collections.ObservableList<T>>
    The items to be displayed in the GridView (as rendered via GridCell instances).
    final void
    setCellFactory(javafx.util.Callback<GridView<T>,GridCell<T>> value)
    Sets the cell factory to use to create GridCell instances to show in the GridView.
    final void
    setCellHeight(double value)
    Sets the height that all cells should be.
    final void
    setCellWidth(double value)
    Sets the width that all cells should be.
    final void
    Sets the amount of horizontal spacing there should be between cells in the same row.
    final void
    setItems(javafx.collections.ObservableList<T> value)
    Sets a new ObservableList as the items list underlying GridView.
    final void
    setVerticalCellSpacing(double value)
    Sets the amount of vertical spacing there should be between cells in the same column.
    final javafx.beans.property.DoubleProperty
    Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).

    Methods inherited from class javafx.scene.control.Control

    computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from class javafx.scene.Node

    accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, 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, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, 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, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Property Details

    • horizontalCellSpacing

      public final javafx.beans.property.DoubleProperty horizontalCellSpacingProperty
      Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).
      See Also:
    • verticalCellSpacing

      public final javafx.beans.property.DoubleProperty verticalCellSpacingProperty
      Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).
      See Also:
    • cellWidth

      public final javafx.beans.property.DoubleProperty cellWidthProperty
      Property representing the width that all cells should be.
      See Also:
    • cellHeight

      public final javafx.beans.property.DoubleProperty cellHeightProperty
      Property representing the height that all cells should be.
      See Also:
    • cellFactory

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<GridView<T>,GridCell<T>>> cellFactoryProperty
      Property representing the cell factory that is currently set in this GridView, or null if no cell factory has been set (in which case the default cell factory provided by the GridView skin will be used). The cell factory is used for instantiating enough GridCell instances for the visible area of the GridView. Refer to the GridView class documentation for more information and examples.
      See Also:
    • items

      public final javafx.beans.property.ObjectProperty<javafx.collections.ObservableList<T>> itemsProperty
      The items to be displayed in the GridView (as rendered via GridCell instances). For example, if the ColorGridCell were being used (as in the case at the top of this class documentation), this items list would be populated with Color values. It is important to appreciate that the items list is used for the data, not the rendering. What is meant by this is that the items list should contain Color values, not the nodes that represent the Color. The actual rendering should be left up to the cell factory, where it will take the Color value and create / update the display as necessary.
      See Also:
  • Constructor Details

    • GridView

      public GridView()
      Creates a default, empty GridView control.
    • GridView

      public GridView(javafx.collections.ObservableList<T> items)
      Creates a default GridView control with the provided items prepopulated.
      Parameters:
      items - The items to display inside the GridView.
  • Method Details

    • createDefaultSkin

      protected javafx.scene.control.Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class javafx.scene.control.Control
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class javafx.scene.layout.Region
    • horizontalCellSpacingProperty

      public final javafx.beans.property.DoubleProperty horizontalCellSpacingProperty()
      Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).
      Returns:
      the horizontalCellSpacing property
      See Also:
    • setHorizontalCellSpacing

      public final void setHorizontalCellSpacing(double value)
      Sets the amount of horizontal spacing there should be between cells in the same row.
      Parameters:
      value - The amount of spacing to use.
    • getHorizontalCellSpacing

      public final double getHorizontalCellSpacing()
      Returns the amount of horizontal spacing there is between cells in the same row.
    • verticalCellSpacingProperty

      public final javafx.beans.property.DoubleProperty verticalCellSpacingProperty()
      Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).
      Returns:
      the verticalCellSpacing property
      See Also:
    • setVerticalCellSpacing

      public final void setVerticalCellSpacing(double value)
      Sets the amount of vertical spacing there should be between cells in the same column.
      Parameters:
      value - The amount of spacing to use.
    • getVerticalCellSpacing

      public final double getVerticalCellSpacing()
      Returns the amount of vertical spacing there is between cells in the same column.
    • cellWidthProperty

      public final javafx.beans.property.DoubleProperty cellWidthProperty()
      Property representing the width that all cells should be.
      Returns:
      the cellWidth property
      See Also:
    • setCellWidth

      public final void setCellWidth(double value)
      Sets the width that all cells should be.
    • getCellWidth

      public final double getCellWidth()
      Returns the width that all cells should be.
    • cellHeightProperty

      public final javafx.beans.property.DoubleProperty cellHeightProperty()
      Property representing the height that all cells should be.
      Returns:
      the cellHeight property
      See Also:
    • setCellHeight

      public final void setCellHeight(double value)
      Sets the height that all cells should be.
    • getCellHeight

      public final double getCellHeight()
      Returns the height that all cells should be.
    • cellFactoryProperty

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<GridView<T>,GridCell<T>>> cellFactoryProperty()
      Property representing the cell factory that is currently set in this GridView, or null if no cell factory has been set (in which case the default cell factory provided by the GridView skin will be used). The cell factory is used for instantiating enough GridCell instances for the visible area of the GridView. Refer to the GridView class documentation for more information and examples.
      Returns:
      the cellFactory property
      See Also:
    • setCellFactory

      public final void setCellFactory(javafx.util.Callback<GridView<T>,GridCell<T>> value)
      Sets the cell factory to use to create GridCell instances to show in the GridView.
    • getCellFactory

      public final javafx.util.Callback<GridView<T>,GridCell<T>> getCellFactory()
      Returns the cell factory that will be used to create GridCell instances to show in the GridView.
    • itemsProperty

      public final javafx.beans.property.ObjectProperty<javafx.collections.ObservableList<T>> itemsProperty()
      The items to be displayed in the GridView (as rendered via GridCell instances). For example, if the ColorGridCell were being used (as in the case at the top of this class documentation), this items list would be populated with Color values. It is important to appreciate that the items list is used for the data, not the rendering. What is meant by this is that the items list should contain Color values, not the nodes that represent the Color. The actual rendering should be left up to the cell factory, where it will take the Color value and create / update the display as necessary.
      Returns:
      the items property
      See Also:
    • setItems

      public final void setItems(javafx.collections.ObservableList<T> value)
      Sets a new ObservableList as the items list underlying GridView. The old items list will be discarded.
    • getItems

      public final javafx.collections.ObservableList<T> getItems()
      Returns the currently-in-use items list that is being used by the GridView.
    • getClassCssMetaData

      public static List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>> getClassCssMetaData()
      Returns:
      The CssMetaData associated with this class, which may include the CssMetaData of its super classes.
    • getControlCssMetaData

      public List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class javafx.scene.control.Control
    • getUserAgentStylesheet

      protected final String getUserAgentStylesheet(Class<?> clazz, String fileName)
      A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once. Caches the external form of the resource.
      Parameters:
      clazz - the class used for the resource lookup
      fileName - the name of the user agent stylesheet
      Returns:
      the external form of the user agent stylesheet (the path)