Top Description Fields Methods
org.controlsfx.control.spreadsheet

public Interface Grid

Known Direct Implementers
org.controlsfx.control.spreadsheet.GridBase
Imports
java.util.Collection, javafx.beans.property.BooleanProperty, javafx.collections.ObservableList, javafx.event.Event, .EventHandler, .EventType

That class holds some SpreadsheetCell in order to be used by the SpreadsheetView. A Grid is used by SpreadsheetView to represent the data to show on screen. A default implementation is provided by GridBase, but for more custom purposes (e.g. loading data on demand), this Grid interface may prove useful.

A Grid at its essence consists of rows and columns. Critical to the SpreadsheetView is that the row count and column count are accurately returned when requested (even if the data returned by getRows() is not all fully loaded into memory).

Whilst the getRows() return type may appear confusing, it is actually quite logical when you think about it: getRows() returns an ObservableList of ObservableList of SpreadsheetCell instances. In other words, this is your classic 2D collection, where the outer ObservableList can be thought of as the rows, and the inner ObservableList as the columns within each row. Therefore, if you are wanting to iterate through all columns in every row of the grid, you would do something like this:

Code Sample

Grid grid = ...
for (int row = 0; row < grid.getRowCount(); row++) {
    for (int column = 0; column < grid.getColumnCount(); column++) {
        SpreadsheetCell<?> cell = getRows().get(row).get(column);
        doStuff(cell);
    }
}

See Also
SpreadsheetView, GridBase, SpreadsheetCell

Field Summary

Modifier and TypeField and Description
public static final double
AUTOFIT

This value may be returned from getRowHeight(int) in order to let the system compute the best row height.

Method Summary

Modifier and TypeMethod and Description
public <E extends Event> void
addEventHandler(EventType<E>
the type of the events to receive by the handler
eventType
,
EventHandler<? super E>
the handler to register
eventHandler
)

Registers an event handler to this Grid.

public BooleanProperty

Returns:

the Boolean property associated with the displayed selecion of the Grid
displaySelectionProperty
()

Returns the Boolean property associated with the displayed selection of the Grid.

public int

Returns:

the number of columns in the Grid.
getColumnCount
()

Returns how many columns are inside the Grid.

public ObservableList<String>

Returns:

an ObservableList of String to display in the column headers
getColumnHeaders
()

Returns an ObservableList of String to display in the column headers.

public int

Returns:

the number of rows in the Grid.
getRowCount
()

Returns how many rows are inside the Grid.

public ObservableList<String>

Returns:

an ObservableList of String to display in the row headers
getRowHeaders
()

Returns an ObservableList of String to display in the row headers.

public double

Returns:

the height in pixels of the given row.
getRowHeight
(int
the row index
row
)

Returns the height of a row.

public ObservableList<ObservableList<SpreadsheetCell>>

Returns:

an ObservableList of ObservableList of SpreadsheetCell instances
getRows
()

Returns an ObservableList of ObservableList of SpreadsheetCell instances.

public boolean

Returns:

true if the given cell will display a selection rectangle
isCellDisplaySelection
(int
the row index
row
,
int
the column index
column
)

Returns true if the given cell will display a selection rectangle when selected.

public boolean

Returns:

true if the selection (black rectangle) is displayed on the Grid
isDisplaySelection
()

Return true if the selection (black rectangle) is displayed on the Grid.

public boolean

Returns:

true if the specified row is resizable
isRowResizable
(int
the row index
row
)

Returns true if the specified row is resizable.

public <E extends Event> void
removeEventHandler(EventType<E>
the event type from which to unregister
eventType
,
EventHandler<? super E>
the handler to unregister
eventHandler
)

Unregisters a previously registered event handler from this Grid.

public void
setCellDisplaySelection(int
the row index
row
,
int
the column index
column
,
boolean
true is the selection should always be displayed on this cell
displaySelection
)

Overrides the value defined by isDisplaySelection() so that no matter what is defined on the grid, the given cell will always have its selection set to the displaySelection parameter.

public void
setCellValue(int
the row index issued from the SpreadsheetCell
row
,
int
the column index issued from the SpreadsheetCell
column
,
Object
the value to set to the SpreadsheetCell
value
)

Changes the value situated at the intersection if possible.

public void
setDisplaySelection(boolean
true if the selection should be displayed
value
)

If set to true, the selection (black rectangle) will be displayed on the Grid.

public void
setRows(Collection<ObservableList<SpreadsheetCell>>
the rows to set for this Grid
rows
)

Sets the rows used by the grid, and updates the rowCount.

public void
spanColumn(int
the span range
count
,
int
the row index
rowIndex
,
int
the column index
colIndex
)

Spans in column the cell situated at rowIndex and colIndex by the number count.

public void
spanRow(int
the span range
count
,
int
the row index
rowIndex
,
int
the column index
colIndex
)

Spans in row the cell situated at rowIndex and colIndex by the number count.

Field Detail

AUTOFITback to summary
public static final double AUTOFIT

This value may be returned from getRowHeight(int) in order to let the system compute the best row height.

Method Detail

addEventHandlerback to summary
public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)

Registers an event handler to this Grid. The Grid class allows registration of listeners which will be notified as a SpreadsheetCell's value will change.

Parameters
eventType:EventType<E>

the type of the events to receive by the handler

eventHandler:EventHandler<? super E>

the handler to register

Exceptions
NullPointerException:
if the event type or handler is null
displaySelectionPropertyback to summary
public BooleanProperty displaySelectionProperty()

Returns the Boolean property associated with the displayed selection of the Grid.

Returns:BooleanProperty

the Boolean property associated with the displayed selecion of the Grid

getColumnCountback to summary
public int getColumnCount()

Returns how many columns are inside the Grid.

Returns:int

the number of columns in the Grid.

getColumnHeadersback to summary
public ObservableList<String> getColumnHeaders()

Returns an ObservableList of String to display in the column headers.

Returns:ObservableList<String>

an ObservableList of String to display in the column headers

getRowCountback to summary
public int getRowCount()

Returns how many rows are inside the Grid.

Returns:int

the number of rows in the Grid.

getRowHeadersback to summary
public ObservableList<String> getRowHeaders()

Returns an ObservableList of String to display in the row headers.

Returns:ObservableList<String>

an ObservableList of String to display in the row headers

getRowHeightback to summary
public double getRowHeight(int row)

Returns the height of a row. AUTOFIT can be returned in order to let the system compute the best row height.

Parameters
row:int

the row index

Returns:double

the height in pixels of the given row.

getRowsback to summary
public ObservableList<ObservableList<SpreadsheetCell>> getRows()

Returns an ObservableList of ObservableList of SpreadsheetCell instances. Refer to the Grid class javadoc for more detail.

Returns:ObservableList<ObservableList<SpreadsheetCell>>

an ObservableList of ObservableList of SpreadsheetCell instances

isCellDisplaySelectionback to summary
public boolean isCellDisplaySelection(int row, int column)

Returns true if the given cell will display a selection rectangle when selected. If nothing is defined for this cell, isDisplaySelection() is returned.

Parameters
row:int

the row index

column:int

the column index

Returns:boolean

true if the given cell will display a selection rectangle

isDisplaySelectionback to summary
public boolean isDisplaySelection()

Return true if the selection (black rectangle) is displayed on the Grid. Cells may override this property with setCellDisplaySelection(int, int, boolean).

Returns:boolean

true if the selection (black rectangle) is displayed on the Grid

isRowResizableback to summary
public boolean isRowResizable(int row)

Returns true if the specified row is resizable.

Parameters
row:int

the row index

Returns:boolean

true if the specified row is resizable

removeEventHandlerback to summary
public <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)

Unregisters a previously registered event handler from this Grid. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler.

Parameters
eventType:EventType<E>

the event type from which to unregister

eventHandler:EventHandler<? super E>

the handler to unregister

Exceptions
NullPointerException:
if the event type or handler is null
setCellDisplaySelectionback to summary
public void setCellDisplaySelection(int row, int column, boolean displaySelection)

Overrides the value defined by isDisplaySelection() so that no matter what is defined on the grid, the given cell will always have its selection set to the displaySelection parameter.

Parameters
row:int

the row index

column:int

the column index

displaySelection:boolean

true is the selection should always be displayed on this cell

setCellValueback to summary
public void setCellValue(int row, int column, Object value)

Changes the value situated at the intersection if possible. Verification and conversion of the value should be done before with SpreadsheetCellType#match(Object) and SpreadsheetCellType#convertValue(Object).

Parameters
row:int

the row index issued from the SpreadsheetCell

column:int

the column index issued from the SpreadsheetCell

value:Object

the value to set to the SpreadsheetCell

setDisplaySelectionback to summary
public void setDisplaySelection(boolean value)

If set to true, the selection (black rectangle) will be displayed on the Grid. Cells may override this property with setCellDisplaySelection(int, int, boolean).

Parameters
value:boolean

true if the selection should be displayed

setRowsback to summary
public void setRows(Collection<ObservableList<SpreadsheetCell>> rows)

Sets the rows used by the grid, and updates the rowCount. This method should be called before the Grid is actually given to a SpreadsheetView. If this method is called after, you should give the Grid again to the SpreadsheetView by using SpreadsheetView#setGrid(org.controlsfx.control.spreadsheet.Grid).

Parameters
rows:Collection<ObservableList<SpreadsheetCell>>

the rows to set for this Grid

spanColumnback to summary
public void spanColumn(int count, int rowIndex, int colIndex)

Spans in column the cell situated at rowIndex and colIndex by the number count.

Parameters
count:int

the span range

rowIndex:int

the row index

colIndex:int

the column index

spanRowback to summary
public void spanRow(int count, int rowIndex, int colIndex)

Spans in row the cell situated at rowIndex and colIndex by the number count.

Parameters
count:int

the span range

rowIndex:int

the row index

colIndex:int

the column index