Top Description Inners Fields Constructors Methods
org.controlsfx.control

public Class GridView<T>

extends ControlsFXControl
Class Inheritance
Imports
impl.org.controlsfx.skin.GridViewSkin, java.util.ArrayList, .Collections, .List, javafx.beans.property.DoubleProperty, .ObjectProperty, .SimpleObjectProperty, javafx.collections.FXCollections, .ObservableList, javafx.css.CssMetaData, .StyleConverter, .Styleable, .StyleableDoubleProperty, .StyleableProperty, javafx.scene.Node, javafx.scene.control.Cell, .Control, .ListCell, .Skin, javafx.scene.paint.Color, javafx.util.Callback, org.controlsfx.control.cell.ColorGridCell

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
GridCell

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Callback<GridView<T>, GridCell<T>>>
private DoubleProperty
private DoubleProperty
private static final String
DEFAULT_STYLE_CLASS

* Stylesheet Handling * *

private DoubleProperty
private ObjectProperty<ObservableList<T>>
private DoubleProperty
verticalCellSpacing

Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).

Constructor Summary

AccessConstructor and Description
public
GridView()

Creates a default, empty GridView control.

public
GridView(ObservableList<T>
The items to display inside the GridView.
items
)

Creates a default GridView control with the provided items prepopulated.

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<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).

public final DoubleProperty
cellHeightProperty()

Property representing the height that all cells should be.

public final DoubleProperty
cellWidthProperty()

Property representing the width that all cells should be.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public final Callback<GridView<T>, GridCell<T>>
getCellFactory()

Returns the cell factory that will be used to create GridCell instances to show in the GridView.

public final double
getCellHeight()

Returns the height that all cells should be.

public final double
getCellWidth()

Returns the width that all cells should be.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

The CssMetaData associated with this class, which may include the CssMetaData of its super classes.
getClassCssMetaData
()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final double
getHorizontalCellSpacing()

Returns the amount of horizontal spacing there is between cells in the same row.

public final ObservableList<T>
getItems()

Returns the currently-in-use items list that is being used by the GridView.

public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

public final double
getVerticalCellSpacing()

Returns the amount of vertical spacing there is between cells in the same column.

public final DoubleProperty
horizontalCellSpacingProperty()

Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).

public final ObjectProperty<ObservableList<T>>
itemsProperty()

The items to be displayed in the GridView (as rendered via GridCell instances).

public final void
setCellFactory(Callback<GridView<T>, GridCell<T>> value)

Sets the cell factory to use to create GridCell instances to show in the GridView.

public final void
setCellHeight(double value)

Sets the height that all cells should be.

public final void
setCellWidth(double value)

Sets the width that all cells should be.

public final void
setHorizontalCellSpacing(double
The amount of spacing to use.
value
)

Sets the amount of horizontal spacing there should be between cells in the same row.

public final void
setItems(ObservableList<T> value)

Sets a new ObservableList as the items list underlying GridView.

public final void
setVerticalCellSpacing(double
The amount of spacing to use.
value
)

Sets the amount of vertical spacing there should be between cells in the same column.

public final DoubleProperty
Inherited from org.controlsfx.control.ControlsFXControl:
getUserAgentStylesheet

Field Detail

cellFactoryback to summary
private ObjectProperty<Callback<GridView<T>, GridCell<T>>> cellFactory
cellHeightback to summary
private DoubleProperty cellHeight
cellWidthback to summary
private DoubleProperty cellWidth
DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS

* Stylesheet Handling * *

horizontalCellSpacingback to summary
private DoubleProperty horizontalCellSpacing
itemsback to summary
private ObjectProperty<ObservableList<T>> items
verticalCellSpacingback to summary
private DoubleProperty verticalCellSpacing

Property for specifying how much spacing there is between each cell in a column (i.e. how much vertical spacing there is).

Constructor Detail

GridViewback to summary
public GridView()

Creates a default, empty GridView control.

GridViewback to summary
public GridView(ObservableList<T> items)

Creates a default GridView control with the provided items prepopulated.

Parameters
items:ObservableList<T>

The items to display inside the GridView.

Method Detail

cellFactoryPropertyback to summary
public final ObjectProperty<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.

cellHeightPropertyback to summary
public final DoubleProperty cellHeightProperty()

Property representing the height that all cells should be.

cellWidthPropertyback to summary
public final DoubleProperty cellWidthProperty()

Property representing the width that all cells should be.

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getCellFactoryback to summary
public final Callback<GridView<T>, GridCell<T>> getCellFactory()

Returns the cell factory that will be used to create GridCell instances to show in the GridView.

getCellHeightback to summary
public final double getCellHeight()

Returns the height that all cells should be.

getCellWidthback to summary
public final double getCellWidth()

Returns the width that all cells should be.

getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Doc from javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

The CssMetaData associated with this class, which may include the CssMetaData of its super classes.

getControlCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Doc from javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
getHorizontalCellSpacingback to summary
public final double getHorizontalCellSpacing()

Returns the amount of horizontal spacing there is between cells in the same row.

getItemsback to summary
public final ObservableList<T> getItems()

Returns the currently-in-use items list that is being used by the GridView.

getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
getVerticalCellSpacingback to summary
public final double getVerticalCellSpacing()

Returns the amount of vertical spacing there is between cells in the same column.

horizontalCellSpacingPropertyback to summary
public final DoubleProperty horizontalCellSpacingProperty()

Property for specifying how much spacing there is between each cell in a row (i.e. how much horizontal spacing there is).

itemsPropertyback to summary
public final ObjectProperty<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.

setCellFactoryback to summary
public final void setCellFactory(Callback<GridView<T>, GridCell<T>> value)

Sets the cell factory to use to create GridCell instances to show in the GridView.

setCellHeightback to summary
public final void setCellHeight(double value)

Sets the height that all cells should be.

setCellWidthback to summary
public final void setCellWidth(double value)

Sets the width that all cells should be.

setHorizontalCellSpacingback to summary
public final void setHorizontalCellSpacing(double value)

Sets the amount of horizontal spacing there should be between cells in the same row.

Parameters
value:double

The amount of spacing to use.

setItemsback to summary
public final void setItems(ObservableList<T> value)

Sets a new ObservableList as the items list underlying GridView. The old items list will be discarded.

setVerticalCellSpacingback to summary
public final void setVerticalCellSpacing(double value)

Sets the amount of vertical spacing there should be between cells in the same column.

Parameters
value:double

The amount of spacing to use.

verticalCellSpacingPropertyback to summary
public final DoubleProperty verticalCellSpacingProperty()
org.controlsfx.control back to summary

private Class GridView.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<GridView<?>, Number>
private static final CssMetaData<GridView<?>, Number>
private static final CssMetaData<GridView<?>, Number>
private static final List<CssMetaData<? extends Styleable, ?>>
private static final CssMetaData<GridView<?>, Number>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CELL_HEIGHTback to summary
private static final CssMetaData<GridView<?>, Number> CELL_HEIGHT
CELL_WIDTHback to summary
private static final CssMetaData<GridView<?>, Number> CELL_WIDTH
HORIZONTAL_CELL_SPACINGback to summary
private static final CssMetaData<GridView<?>, Number> HORIZONTAL_CELL_SPACING
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES
VERTICAL_CELL_SPACINGback to summary
private static final CssMetaData<GridView<?>, Number> VERTICAL_CELL_SPACING

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()