Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class DataGrid

  1. Object
  2. Component
  3. ScrollSurface
  4. DataGrid

ImplementsAnimation, Editable, StyleListener

A grid of data for large sets: a TableModel or a tree of rows, with sorting, filtering, grouping, frozen columns, resizable and movable columns, selection, keyboard navigation and editing in place.

The grid paints its cells itself, like the com.codename1.ui.scheduler views. There is no component per cell or per row: only the rows on screen are painted, sorting and filtering move row numbers in an array and never the data, and opening a node of a tree costs what it shows. A million rows scroll as one hundred do. Table, which lays out a component per cell, is the class for a small form laid out as a table.

TableModel model = new DefaultTableModel(new String[]{"Name", "Team", "Score"}, new Object[][]{
        {"dana", "red", 7}, {"Ann", "blue", 3}, {"carl", "red", 9}}, true);
Form form = new Form("Scores", new BorderLayout());
DataGrid grid = new DataGrid(model);
grid.getColumn(0).setFlex(1);
grid.getColumn(2).setKind(GridColumn.Kind.NUMBER).setAggregate(GridAggregate.SUM);
grid.setFrozenColumns(1);
grid.sortBy(grid.getColumn(2), false);
form.add(BorderLayout.CENTER, grid);
form.show();

Rows

A row number of the grid is a view row: an index into what is shown after filtering, sorting, grouping and the opening of nodes. It is not a row of the model; getModelRow(int) and getNode(int) translate it.

Trees

Built over a TreeTableModel, the grid is a tree table: the tree column (setTreeColumn, the first visible one by default) shows each node indented under its parent with an arrow that opens it. Children are asked of the model when a node is first opened. Sorting orders siblings.

Editing

A cell is edited when its column and its model both allow it. A boolean toggles with a tap. Any other value is edited by its column’s GridCellEditor, which supplies a component the grid lays over the cell while it is edited and removes afterwards: a text field, or a picker for a date or a choice.

Styles

DataGrid (the background), DataGridHeader, DataGridRow and its selected state, DataGridRowAlt (every other row), DataGridGroupRow, DataGridLine (the foreground is the colour of the grid lines), DataGridCheck and DataGridEditor. Only colours, fonts and paddings are read; nothing has a border.

Nested types

enum DataGrid.SelectionModeWhat a tap selects.

Constructors

public DataGrid()A grid with no data.
public DataGrid(TableModel model)A grid over the rows of a table model, with a column for each of its columns.
public DataGrid(TreeTableModel model)A tree grid over a tree table model, with a column for each of its columns.

Methods

public final void setModel(TableModel model)Shows the rows of a table model, with a column for each of its columns.
public final void setModel(TreeTableModel model)Shows the nodes of a tree table model, with a column for each of its columns.
public TableModel getTableModel()The table model shown, or null for a tree grid.
public TreeTableModel getTreeModel()The tree model shown, or null for a flat grid.
public boolean isTree()Whether this is a tree grid.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public void refresh()Reads the model again: filters, sorts and groups its rows anew and keeps the selection on the same rows where they are still shown.
public void refreshNode(Object node)Asks the tree model again for the children of one node, and shows them.
public List<GridColumn> getColumns()The columns, in the order they are shown, hidden ones included.
public int getColumnCount()How many columns there are, hidden ones included.
public GridColumn getColumn(int index)The column at a place in the order, hidden ones counted.
public GridColumn getColumnForModel(int modelColumn)The column showing a column of the model, or null.
public void setColumns(GridColumn... cols)Replaces the columns.
public void addColumn(GridColumn c)Adds a column at the end.
public void removeColumn(GridColumn c)Removes a column.
public void moveColumn(int from, int to)Moves the column at from in the order to to, hidden ones counted.
public void refreshColumns()Asks the grid to lay its columns out again, after a column’s width, title or visibility changed.
public int getFrozenColumns()How many of the first visible columns stay in place while the rest scroll sideways.
public void setFrozenColumns(int count)Sets how many of the first visible columns stay in place while the rest scroll sideways; 0 by default.
public GridColumn getTreeColumn()The column a tree grid draws the tree in, or null for the first visible one.
public void setTreeColumn(GridColumn c)Sets the column a tree grid draws the tree in; null, the default, is the first visible one.
public void sortBy(GridColumn c, boolean ascending)Sorts by one column alone.
public void addSort(GridColumn c, boolean ascending)Adds a column to sort by after the ones already sorted by, or changes its direction when it is one of them.
public void clearSort()Stops sorting: rows are shown in the model’s order.
public List<GridColumn> getSortColumns()The columns sorted by, most significant first.
public int getSortDirection(GridColumn c)1 when sorted by c ascending, -1 descending, 0 when not sorted by it.
public GridFilter getFilter()The filter of the rows, or null.
public void setFilter(GridFilter filter)Shows only the rows a filter accepts; null shows them all.
public GridColumn getGroupColumn()The column the rows are grouped by, or null.
public void setGroupColumn(GridColumn c)Groups the rows by the values of a column, each group under a row of its own that opens and closes it; null stops grouping.
public int getRowCount()How many rows are shown, group rows included.
public Object getValueAt(int row, GridColumn c)The value a view row shows in a column.
public void setValueAt(int row, GridColumn c, Object value)Sets the value of a view row in a column, through the model.
public int getModelRow(int row)The model row a view row shows, or -1 for a group row or in a tree grid.
public int getViewRow(int modelRow)The view row showing a model row, or -1 when it is filtered out or in a closed group.
public Object getNode(int row)The node a view row of a tree grid shows, or null.
public int getRowOfNode(Object node)The view row showing a node, or -1 when it is not shown.
public boolean isGroupRow(int row)Whether a view row is a group row.
public int getDepth(int row)How deep a view row is in the tree: 0 for a root.
public boolean isExpandable(int row)Whether a view row can be opened: a node that is not a leaf, or a group.
public boolean isExpanded(int row)Whether a view row is open.
public void setExpanded(int row, boolean open)Opens or closes a view row: a node of a tree, or a group.
public void setNodeExpanded(Object node, boolean open)Opens or closes a node of a tree grid, whether it is shown or not; a node that is not shown opens the next time it is.
public boolean isNodeExpanded(Object node)Whether a node of a tree grid is open.
public void expandAll()Opens every row.
public void collapseAll()Closes every row.
public DataGrid.SelectionMode getSelectionMode()What a tap selects.
public void setSelectionMode(DataGrid.SelectionMode mode)Sets what a tap selects; MULTIPLE_ROWS by default.
public int getSelectedRow()The row the keyboard is on, the last one chosen, or -1.
public int getSelectedColumn()The visible column index of the cell the keyboard is on.
public int[] getSelectedRows()The selected view rows, in order.
public int getSelectedRowCount()How many rows are selected.
public boolean isRowSelected(int row)Whether a view row is selected.
public void setSelectedRow(int row)Selects one view row and moves the keyboard to it; -1 clears the selection.
public void selectRows(int from, int to, boolean add)Selects a range of view rows, adding to the selection when add.
public void selectAll()Selects every row.
public void clearSelection()Selects nothing.
public void addSelectionListener(SelectionListener l)Listens to changes of the selection.
public void removeSelectionListener(SelectionListener l)Stops listening to changes of the selection.
public void addActionListener(ActionListener l)Listens to rows being opened: a double tap, or Enter on a cell that is not edited.
public void removeActionListener(ActionListener l)Stops listening to rows being opened.
public float getRowHeightMM()The height of a row in millimetres, 0 for the height of the font.
public void setRowHeightMM(float mm)Sets the height of a row in millimetres; 0, the default, fits the row style’s font and padding.
public int getRowHeight()The height of a row, in pixels, as last laid out.
public boolean isHeaderVisible()Whether the header row is shown.
public void setHeaderVisible(boolean v)Shows or hides the header row.
public boolean isStriped()Whether every other row is painted in DataGridRowAlt.
public void setStriped(boolean striped)Sets whether every other row is painted in DataGridRowAlt.
public void setGridLines(boolean horizontal, boolean vertical)Sets which grid lines are drawn.
public String getEmptyText()The text shown when there are no rows.
public void setEmptyText(String text)Sets the text shown when there are no rows; empty by default.
public GridCellRenderer getDefaultRenderer()The renderer of a column that has none.
public void setDefaultRenderer(GridCellRenderer r)Sets the renderer of a column that has none.
public GridCellEditor getDefaultEditor()The editor of a column that has none.
public void setDefaultEditor(GridCellEditor e)Sets the editor of a column that has none.
protected void layoutSurface(int width, int height)Lays the surface out for a size: sets the header sizes and whatever the content’s size depends on.
protected int getContentWidth()The width of what scrolls, in pixels, without the left header.
protected int getContentHeight()The height of what scrolls, in pixels, without the top header.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
protected int getPageStep(int bodyHeight)How far down a page of content height bodyHeight goes before the next one starts.
protected void paintContent(Graphics g, int x, int y)Paints what scrolls.
protected void paintLeftHeader(Graphics g, int x, int y)Paints the pinned left column.
protected void paintTopHeader(Graphics g, int x, int y)Paints the pinned top row.
protected void paintCorner(Graphics g, int x, int y)Paints the corner where the two headers meet, at its top left.
protected void paintOverlay(Graphics g, int x, int y)Paints over everything, in the component’s own bounds, whose top left is x, y.
public void getCellBounds(int row, int column, int[] out)The bounds of a cell in the grid’s own coordinates: x, y, width, height.
public GridColumn[] getVisibleColumns()The columns shown, in order: the ones getSelectedColumn() and getCellBounds count.
public void scrollToCell(int row, int column)Scrolls so a view row is shown, and a visible column too when it is 0 or more.
protected void pressStarted(int x, int y)The pointer went down at a point, in the component’s coordinates.
protected void tapped(int x, int y, boolean doubleTap)A tap that was not a drag or a long press.
protected boolean editStarted(int x, int y, ScrollSurface.EditTrigger trigger)Asked when a drag or a long press begins, at the point where the pointer went down, in the component’s coordinates.
protected void editMoved(int x, int y)The pointer of an edit moved, or the surface scrolled under it.
protected void editEnded(boolean committed)The edit is over.
protected boolean isEditAutoScroll(int x, int y)Whether the surface scrolls under an edit dragged near its edge.
protected void hoverAt(int x, int y)The pointer rests at a point of the surface without being pressed.
protected void scrollChanged()The scroll position changed.
public boolean handlesInput()Prevents key events from being grabbed for focus traversal.
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
public boolean isEditing()Whether a cell is being edited.
public int getEditingRow()The view row being edited, or -1.
public GridColumn getEditingColumn()The column being edited, or null.
public boolean editCellAt(int row, int column)Edits a cell, when it may be edited.
public void commitEdit()Ends the edit, writing the editor’s value to the model.
public final void cancelEdit()Ends the edit without changing the model, and any drag in progress.

Inherited nested types

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

DataGrid

public DataGrid()
A grid with no data.

DataGrid

public DataGrid(TableModel model)
A grid over the rows of a table model, with a column for each of its columns.

DataGrid

public DataGrid(TreeTableModel model)
A tree grid over a tree table model, with a column for each of its columns.

Method details

setModel

public final void setModel(TableModel model)
Shows the rows of a table model, with a column for each of its columns. Sorting, filtering and grouping are kept when their columns still exist.

setModel

public final void setModel(TreeTableModel model)
Shows the nodes of a tree table model, with a column for each of its columns. The roots are shown closed.

getTableModel

public TableModel getTableModel()
The table model shown, or null for a tree grid.

getTreeModel

public TreeTableModel getTreeModel()
The tree model shown, or null for a flat grid.

isTree

public boolean isTree()
Whether this is a tree grid.

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

refresh

public void refresh()
Reads the model again: filters, sorts and groups its rows anew and keeps the selection on the same rows where they are still shown.

refreshNode

public void refreshNode(Object node)
Asks the tree model again for the children of one node, and shows them. Use it after the children of a node changed; refresh() reads the whole tree again.

getColumns

public List<GridColumn> getColumns()
The columns, in the order they are shown, hidden ones included.

getColumnCount

public int getColumnCount()
How many columns there are, hidden ones included.

getColumn

public GridColumn getColumn(int index)
The column at a place in the order, hidden ones counted.

getColumnForModel

public GridColumn getColumnForModel(int modelColumn)
The column showing a column of the model, or null.

setColumns

public void setColumns(GridColumn... cols)
Replaces the columns. A model column with no GridColumn is not shown, and one may be shown twice.

addColumn

public void addColumn(GridColumn c)
Adds a column at the end.

removeColumn

public void removeColumn(GridColumn c)
Removes a column.

moveColumn

public void moveColumn(int from, int to)
Moves the column at from in the order to to, hidden ones counted.

refreshColumns

public void refreshColumns()
Asks the grid to lay its columns out again, after a column’s width, title or visibility changed.

getFrozenColumns

public int getFrozenColumns()
How many of the first visible columns stay in place while the rest scroll sideways.

setFrozenColumns

public void setFrozenColumns(int count)
Sets how many of the first visible columns stay in place while the rest scroll sideways; 0 by default.

getTreeColumn

public GridColumn getTreeColumn()
The column a tree grid draws the tree in, or null for the first visible one.

setTreeColumn

public void setTreeColumn(GridColumn c)
Sets the column a tree grid draws the tree in; null, the default, is the first visible one.

sortBy

public void sortBy(GridColumn c, boolean ascending)
Sorts by one column alone.

addSort

public void addSort(GridColumn c, boolean ascending)
Adds a column to sort by after the ones already sorted by, or changes its direction when it is one of them.

clearSort

public void clearSort()
Stops sorting: rows are shown in the model’s order.

getSortColumns

public List<GridColumn> getSortColumns()
The columns sorted by, most significant first.

getSortDirection

public int getSortDirection(GridColumn c)
1 when sorted by c ascending, -1 descending, 0 when not sorted by it.

getFilter

public GridFilter getFilter()
The filter of the rows, or null.

setFilter

public void setFilter(GridFilter filter)
Shows only the rows a filter accepts; null shows them all.

getGroupColumn

public GridColumn getGroupColumn()
The column the rows are grouped by, or null.

setGroupColumn

public void setGroupColumn(GridColumn c)

Groups the rows by the values of a column, each group under a row of its own that opens and closes it; null stops grouping. A tree grid is never grouped.

Groups are ordered by their value, in the column’s sort direction when it is sorted by, and the group rows show the column’s GridAggregates.

getRowCount

public int getRowCount()
How many rows are shown, group rows included.

getValueAt

public Object getValueAt(int row, GridColumn c)
The value a view row shows in a column.

setValueAt

public void setValueAt(int row, GridColumn c, Object value)
Sets the value of a view row in a column, through the model.

getModelRow

public int getModelRow(int row)
The model row a view row shows, or -1 for a group row or in a tree grid.

getViewRow

public int getViewRow(int modelRow)
The view row showing a model row, or -1 when it is filtered out or in a closed group.

getNode

public Object getNode(int row)
The node a view row of a tree grid shows, or null.

getRowOfNode

public int getRowOfNode(Object node)
The view row showing a node, or -1 when it is not shown.

isGroupRow

public boolean isGroupRow(int row)
Whether a view row is a group row.

getDepth

public int getDepth(int row)
How deep a view row is in the tree: 0 for a root.

isExpandable

public boolean isExpandable(int row)
Whether a view row can be opened: a node that is not a leaf, or a group.

isExpanded

public boolean isExpanded(int row)
Whether a view row is open.

setExpanded

public void setExpanded(int row, boolean open)
Opens or closes a view row: a node of a tree, or a group.

setNodeExpanded

public void setNodeExpanded(Object node, boolean open)
Opens or closes a node of a tree grid, whether it is shown or not; a node that is not shown opens the next time it is.

isNodeExpanded

public boolean isNodeExpanded(Object node)
Whether a node of a tree grid is open.

expandAll

public void expandAll()
Opens every row. In a tree grid this loads the whole tree.

collapseAll

public void collapseAll()
Closes every row.

getSelectionMode

public DataGrid.SelectionMode getSelectionMode()
What a tap selects.

setSelectionMode

public void setSelectionMode(DataGrid.SelectionMode mode)
Sets what a tap selects; MULTIPLE_ROWS by default.

getSelectedRow

public int getSelectedRow()
The row the keyboard is on, the last one chosen, or -1.

getSelectedColumn

public int getSelectedColumn()
The visible column index of the cell the keyboard is on.

getSelectedRows

public int[] getSelectedRows()
The selected view rows, in order.

getSelectedRowCount

public int getSelectedRowCount()
How many rows are selected.

isRowSelected

public boolean isRowSelected(int row)
Whether a view row is selected.

setSelectedRow

public void setSelectedRow(int row)
Selects one view row and moves the keyboard to it; -1 clears the selection.

selectRows

public void selectRows(int from, int to, boolean add)
Selects a range of view rows, adding to the selection when add.

selectAll

public void selectAll()
Selects every row.

clearSelection

public void clearSelection()
Selects nothing.

addSelectionListener

public void addSelectionListener(SelectionListener l)
Listens to changes of the selection. The values given are the row the keyboard was on and is on now; read the rest from the grid.

removeSelectionListener

public void removeSelectionListener(SelectionListener l)
Stops listening to changes of the selection.

addActionListener

public void addActionListener(ActionListener l)
Listens to rows being opened: a double tap, or Enter on a cell that is not edited. The selected row is the one opened.

removeActionListener

public void removeActionListener(ActionListener l)
Stops listening to rows being opened.

getRowHeightMM

public float getRowHeightMM()
The height of a row in millimetres, 0 for the height of the font.

setRowHeightMM

public void setRowHeightMM(float mm)
Sets the height of a row in millimetres; 0, the default, fits the row style’s font and padding.

getRowHeight

public int getRowHeight()
The height of a row, in pixels, as last laid out.

isHeaderVisible

public boolean isHeaderVisible()
Whether the header row is shown.

setHeaderVisible

public void setHeaderVisible(boolean v)
Shows or hides the header row.

isStriped

public boolean isStriped()
Whether every other row is painted in DataGridRowAlt.

setStriped

public void setStriped(boolean striped)
Sets whether every other row is painted in DataGridRowAlt.

setGridLines

public void setGridLines(boolean horizontal, boolean vertical)
Sets which grid lines are drawn.

getEmptyText

public String getEmptyText()
The text shown when there are no rows.

setEmptyText

public void setEmptyText(String text)
Sets the text shown when there are no rows; empty by default.

getDefaultRenderer

public GridCellRenderer getDefaultRenderer()
The renderer of a column that has none.

setDefaultRenderer

public void setDefaultRenderer(GridCellRenderer r)
Sets the renderer of a column that has none.

getDefaultEditor

public GridCellEditor getDefaultEditor()
The editor of a column that has none.

setDefaultEditor

public void setDefaultEditor(GridCellEditor e)
Sets the editor of a column that has none.

layoutSurface

protected void layoutSurface(int width, int height)
Lays the surface out for a size: sets the header sizes and whatever the content’s size depends on. Called before every paint and every pointer event, so it has to return at once when nothing has changed.

getContentWidth

protected int getContentWidth()
The width of what scrolls, in pixels, without the left header.

getContentHeight

protected int getContentHeight()
The height of what scrolls, in pixels, without the top header.

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

getPageStep

protected int getPageStep(int bodyHeight)
How far down a page of content height bodyHeight goes before the next one starts. A view of rows answers a whole number of them, so no page ends in the middle of one.

paintContent

protected void paintContent(Graphics g, int x, int y)
Paints what scrolls. x and y are where the content’s own origin is on screen, which is off screen once it has scrolled. The graphics is clipped to the content region.

paintLeftHeader

protected void paintLeftHeader(Graphics g, int x, int y)
Paints the pinned left column. x is its left; y is where the content’s origin is.

paintTopHeader

protected void paintTopHeader(Graphics g, int x, int y)
Paints the pinned top row. x is where the content’s origin is; y is the top of the row.

paintCorner

protected void paintCorner(Graphics g, int x, int y)
Paints the corner where the two headers meet, at its top left.

paintOverlay

protected void paintOverlay(Graphics g, int x, int y)
Paints over everything, in the component’s own bounds, whose top left is x, y. Not painted on a printed page: it is for what a gesture in progress shows.

getCellBounds

public void getCellBounds(int row, int column, int[] out)
The bounds of a cell in the grid’s own coordinates: x, y, width, height. column is an index among the visible columns.

getVisibleColumns

public GridColumn[] getVisibleColumns()
The columns shown, in order: the ones getSelectedColumn() and getCellBounds count.

scrollToCell

public void scrollToCell(int row, int column)
Scrolls so a view row is shown, and a visible column too when it is 0 or more.

pressStarted

protected void pressStarted(int x, int y)
The pointer went down at a point, in the component’s coordinates. Whatever it turns into – a tap, a drag, a long press – follows.

tapped

protected void tapped(int x, int y, boolean doubleTap)
A tap that was not a drag or a long press.

editStarted

protected boolean editStarted(int x, int y, ScrollSurface.EditTrigger trigger)
Asked when a drag or a long press begins, at the point where the pointer went down, in the component’s coordinates.

Parameters

x int
Not documented.
y int
Not documented.
trigger ScrollSurface.EditTrigger
what kind of gesture it is

Returns

true when an edit has begun and the drag belongs to it; false to pan

editMoved

protected void editMoved(int x, int y)
The pointer of an edit moved, or the surface scrolled under it.

editEnded

protected void editEnded(boolean committed)
The edit is over. committed is false when it was cancelled: by cancelEdit, a second finger, or the surface leaving the form.

isEditAutoScroll

protected boolean isEditAutoScroll(int x, int y)
Whether the surface scrolls under an edit dragged near its edge. Asked on every move of an edit; true by default.

hoverAt

protected void hoverAt(int x, int y)
The pointer rests at a point of the surface without being pressed. A view answers with setHoverTarget, naming what is there and the cursor that says what a press would do.

scrollChanged

protected void scrollChanged()
The scroll position changed.

handlesInput

public boolean handlesInput()
Prevents key events from being grabbed for focus traversal. E.g. a list component might use the arrow keys for internal navigation so it will switch this flag to true in order to prevent the focus manager from moving to the next component.

Returns

true if key events are being used for focus traversal ; otherwise false

keyPressed

public void keyPressed(int keyCode)
If this Component is focused, the key pressed event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

isEditing

public boolean isEditing()
Whether a cell is being edited.

Returns

True if the component is currently being edited.

getEditingRow

public int getEditingRow()
The view row being edited, or -1.

getEditingColumn

public GridColumn getEditingColumn()
The column being edited, or null.

editCellAt

public boolean editCellAt(int row, int column)
Edits a cell, when it may be edited. column is an index among the visible columns. A boolean is toggled at once; anything else gets its column’s editor over the cell.

Returns

true when the cell is being edited, or was toggled

commitEdit

public void commitEdit()
Ends the edit, writing the editor’s value to the model.

cancelEdit

public final void cancelEdit()
Ends the edit without changing the model, and any drag in progress.