- All Known Implementing Classes:
GridBase
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:
-
Property Summary
PropertiesTypePropertyDescriptionjavafx.beans.property.BooleanProperty
Returns the Boolean property associated with the displayed selection of theGrid
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
This value may be returned fromgetRowHeight(int)
in order to let the system compute the best row height. -
Method Summary
Modifier and TypeMethodDescription<E extends javafx.event.Event>
voidaddEventHandler
(javafx.event.EventType<E> eventType, javafx.event.EventHandler<? super E> eventHandler) Registers an event handler to this Grid.javafx.beans.property.BooleanProperty
Returns the Boolean property associated with the displayed selection of theGrid
.int
Returns how many columns are inside theGrid
.javafx.collections.ObservableList
<String> Returns anObservableList
ofString
to display in the column headers.int
Returns how many rows are inside theGrid
.javafx.collections.ObservableList
<String> Returns anObservableList
ofString
to display in the row headers.double
getRowHeight
(int row) Returns the height of a row.javafx.collections.ObservableList
<javafx.collections.ObservableList<SpreadsheetCell>> getRows()
boolean
isCellDisplaySelection
(int row, int column) Returns true if the given cell will display a selection rectangle when selected.boolean
Returntrue
if the selection (black rectangle) is displayed on theGrid
.boolean
isRowResizable
(int row) Returns true if the specified row is resizable.<E extends javafx.event.Event>
voidremoveEventHandler
(javafx.event.EventType<E> eventType, javafx.event.EventHandler<? super E> eventHandler) Unregisters a previously registered event handler from this Grid.void
setCellDisplaySelection
(int row, int column, boolean displaySelection) Overrides the value defined byisDisplaySelection()
so that no matter what is defined on the grid, the given cell will always have its selection set to the displaySelection parameter.void
setCellValue
(int row, int column, Object value) Changes the value situated at the intersection if possible.void
setDisplaySelection
(boolean value) If set to true, the selection (black rectangle) will be displayed on theGrid
.void
setRows
(Collection<javafx.collections.ObservableList<SpreadsheetCell>> rows) Sets the rows used by the grid, and updates the rowCount.void
spanColumn
(int count, int rowIndex, int colIndex) Spans in column the cell situated at rowIndex and colIndex by the number count.void
spanRow
(int count, int rowIndex, int colIndex) Spans in row the cell situated at rowIndex and colIndex by the number count.
-
Property Details
-
displaySelection
javafx.beans.property.BooleanProperty displaySelectionPropertyReturns the Boolean property associated with the displayed selection of theGrid
.- See Also:
-
-
Field Details
-
AUTOFIT
static final double AUTOFITThis value may be returned fromgetRowHeight(int)
in order to let the system compute the best row height.- See Also:
-
-
Method Details
-
getRowCount
int getRowCount()Returns how many rows are inside theGrid
.- Returns:
- the number of rows in the
Grid
.
-
getColumnCount
int getColumnCount()Returns how many columns are inside theGrid
.- Returns:
- the number of columns in the
Grid
.
-
getRows
javafx.collections.ObservableList<javafx.collections.ObservableList<SpreadsheetCell>> getRows()Returns anObservableList
ofObservableList
ofSpreadsheetCell
instances. Refer to theGrid
class javadoc for more detail.- Returns:
- an
ObservableList
ofObservableList
ofSpreadsheetCell
instances
-
setCellValue
Changes the value situated at the intersection if possible. Verification and conversion of the value should be done before withSpreadsheetCellType.match(Object)
andSpreadsheetCellType.convertValue(Object)
.- Parameters:
row
- the row index issued from theSpreadsheetCell
column
- the column index issued from theSpreadsheetCell
value
- the value to set to theSpreadsheetCell
-
getRowHeight
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
- the row index- Returns:
- the height in pixels of the given row.
-
isRowResizable
boolean isRowResizable(int row) Returns true if the specified row is resizable.- Parameters:
row
- the row index- Returns:
true
if the specified row is resizable
-
getRowHeaders
javafx.collections.ObservableList<String> getRowHeaders()Returns anObservableList
ofString
to display in the row headers.- Returns:
- an
ObservableList
ofString
to display in the row headers
-
getColumnHeaders
javafx.collections.ObservableList<String> getColumnHeaders()Returns anObservableList
ofString
to display in the column headers.- Returns:
- an
ObservableList
ofString
to display in the column headers
-
spanRow
void spanRow(int count, int rowIndex, int colIndex) Spans in row the cell situated at rowIndex and colIndex by the number count.- Parameters:
count
- the span rangerowIndex
- the row indexcolIndex
- the column index
-
spanColumn
void spanColumn(int count, int rowIndex, int colIndex) Spans in column the cell situated at rowIndex and colIndex by the number count.- Parameters:
count
- the span rangerowIndex
- the row indexcolIndex
- the column index
-
setRows
Sets the rows used by the grid, and updates the rowCount. This method should be called before theGrid
is actually given to aSpreadsheetView
. If this method is called after, you should give theGrid
again to theSpreadsheetView
by usingSpreadsheetView.setGrid(org.controlsfx.control.spreadsheet.Grid)
.- Parameters:
rows
- the rows to set for thisGrid
-
isDisplaySelection
boolean isDisplaySelection()Returntrue
if the selection (black rectangle) is displayed on theGrid
. Cells may override this property withsetCellDisplaySelection(int, int, boolean)
.- Returns:
true
if the selection (black rectangle) is displayed on the Grid
-
setDisplaySelection
void setDisplaySelection(boolean value) If set to true, the selection (black rectangle) will be displayed on theGrid
. Cells may override this property withsetCellDisplaySelection(int, int, boolean)
.- Parameters:
value
-true
if the selection should be displayed
-
displaySelectionProperty
javafx.beans.property.BooleanProperty displaySelectionProperty()Returns the Boolean property associated with the displayed selection of theGrid
.- Returns:
- the Boolean property associated with the displayed selecion of the
Grid
- See Also:
-
setCellDisplaySelection
void setCellDisplaySelection(int row, int column, boolean displaySelection) Overrides the value defined byisDisplaySelection()
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
- the row indexcolumn
- the column indexdisplaySelection
-true
is the selection should always be displayed on this cell
-
isCellDisplaySelection
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
- the row indexcolumn
- the column index- Returns:
true
if the given cell will display a selection rectangle
-
addEventHandler
<E extends javafx.event.Event> void addEventHandler(javafx.event.EventType<E> eventType, javafx.event.EventHandler<? super E> eventHandler) Registers an event handler to this Grid. The Grid class allows registration of listeners which will be notified as aSpreadsheetCell
's value will change.- Type Parameters:
E
-- Parameters:
eventType
- the type of the events to receive by the handlereventHandler
- the handler to register- Throws:
NullPointerException
- if the event type or handler is null
-
removeEventHandler
<E extends javafx.event.Event> void removeEventHandler(javafx.event.EventType<E> eventType, javafx.event.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.- Type Parameters:
E
-- Parameters:
eventType
- the event type from which to unregistereventHandler
- the handler to unregister- Throws:
NullPointerException
- if the event type or handler is null
-