Class DataGrid
- All Implemented Interfaces:
Animation, 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 Class Summary
Nested ClassesNested classes/interfaces inherited from class ScrollSurface
ScrollSurface.EditTrigger, ScrollSurface.PageGrid -
Field Summary
Fields inherited from class ScrollSurface
HOVER_MS, LIFT_MS, SETTLE_MSFields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
ConstructorsConstructorDescriptionDataGrid()A grid with no data.DataGrid(TableModel model) A grid over the rows of a table model, with a column for each of its columns.DataGrid(TreeTableModel model) A tree grid over a tree table model, with a column for each of its columns. -
Method Summary
Modifier and TypeMethodDescriptionvoidListens to rows being opened: a double tap, or Enter on a cell that is not edited.voidAdds a column at the end.voidListens to changes of the selection.voidaddSort(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.protected DimensionCalculates the preferred size based on component content.final voidEnds the edit without changing the model, and any drag in progress.voidSelects nothing.voidStops sorting: rows are shown in the model's order.voidCloses every row.voidEnds the edit, writing the editor's value to the model.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.booleaneditCellAt(int row, int column) Edits a cell, when it may be edited.protected voideditEnded(boolean committed) The edit is over.protected voideditMoved(int x, int y) The pointer of an edit moved, or the surface scrolled under it.protected booleaneditStarted(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.voidOpens every row.voidgetCellBounds(int row, int column, int[] out) The bounds of a cell in the grid's own coordinates: x, y, width, height.The picker set with#setCellPicker(GridCellPicker).getColumn(int index) The column at a place in the order, hidden ones counted.intHow many columns there are, hidden ones included.getColumnForModel(int modelColumn) The column showing a column of the model, or null.The columns, in the order they are shown, hidden ones included.protected intThe height of what scrolls, in pixels, without the top header.protected intThe width of what scrolls, in pixels, without the left header.The editor of a column that has none.The renderer of a column that has none.intgetDepth(int row) How deep a view row is in the tree: 0 for a root.The column being edited, or null.intThe view row being edited, or -1.The text shown when there are no rows.The filter of the rows, or null.intHow many of the first visible columns stay in place while the rest scroll sideways.The column the rows are grouped by, or null.intgetModelRow(int row) The model row a view row shows, or -1 for a group row or in a tree grid.getNode(int row) The node a view row of a tree grid shows, or null.The painter set with#setOverlayPainter(com.codename1.ui.Painter).protected intgetPageStep(int bodyHeight) How far down a page of content heightbodyHeightgoes before the next one starts.intHow many rows are shown, group rows included.intThe height of a row, in pixels, as last laid out.floatThe height of a row in millimetres, 0 for the height of the font.intgetRowOfNode(Object node) The view row showing a node, or -1 when it is not shown.intThe visible column index of the cell the keyboard is on.intThe row the keyboard is on, the last one chosen, or -1.intHow many rows are selected.int[]The selected view rows, in order.What a tap selects.The columns sorted by, most significant first.int1 when sorted bycascending, -1 descending, 0 when not sorted by it.The table model shown, or null for a tree grid.The column a tree grid draws the tree in, or null for the first visible one.The tree model shown, or null for a flat grid.getValueAt(int row, GridColumn c) The value a view row shows in a column.intgetViewRow(int modelRow) The view row showing a model row, or -1 when it is filtered out or in a closed group.The columns shown, in order: the onesgetSelectedColumn()andgetCellBoundscount.booleanPrevents key events from being grabbed for focus traversal.protected voidhoverAt(int x, int y) The pointer rests at a point of the surface without being pressed.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component stateprotected booleanisEditAutoScroll(int x, int y) Whether the surface scrolls under an edit dragged near its edge.booleanWhether a cell is being edited.booleanisExpandable(int row) Whether a view row can be opened: a node that is not a leaf, or a group.booleanisExpanded(int row) Whether a view row is open.booleanisGroupRow(int row) Whether a view row is a group row.booleanWhether the header row is shown.protected booleanRight to left the grid is mirrored: the first column, and the frozen ones, are at the right, and it scrolls toward the left.booleanisNodeExpanded(Object node) Whether a node of a tree grid is open.booleanisRowSelected(int row) Whether a view row is selected.booleanWhether every other row is painted inDataGridRowAlt.booleanisTree()Whether this is a tree grid.voidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodprotected voidlayoutSurface(int width, int height) Lays the surface out for a size: sets the header sizes and whatever the content's size depends on.voidmoveColumn(int from, int to) Moves the column atfromin the order toto, hidden ones counted.protected voidpaintContent(Graphics g, int x, int y) Paints what scrolls.protected voidpaintCorner(Graphics g, int x, int y) Paints the corner where the two headers meet, at its top left.protected voidpaintLeftHeader(Graphics g, int x, int y) Paints the pinned left column.protected voidpaintOverlay(Graphics g, int x, int y) Paints over everything, in the component's own bounds, whose top left isx,y.protected voidpaintTopHeader(Graphics g, int x, int y) Paints the pinned top row.protected voidpressStarted(int x, int y) The pointer went down at a point, in the component's coordinates.voidrefresh()Reads the model again: filters, sorts and groups its rows anew and keeps the selection on the same rows where they are still shown.voidAsks the grid to lay its columns out again, after a column's width, title or visibility changed.voidrefreshNode(Object node) Asks the tree model again for the children of one node, and shows them.voidStops listening to rows being opened.voidRemoves a column.voidStops listening to changes of the selection.protected voidThe scroll position changed.voidscrollToCell(int row, int column) Scrolls so a view row is shown, and a visible column too when it is 0 or more.voidSelects every row.voidselectRows(int from, int to, boolean add) Selects a range of view rows, adding to the selection whenadd.voidsetCellPicker(GridCellPicker picker) Sets what takes the taps on cells while it asks for them, as the formula editor of a spreadsheet does to put the tapped cell's reference into a formula.voidsetColumns(GridColumn... cols) Replaces the columns.voidSets the editor of a column that has none.voidSets the renderer of a column that has none.voidsetEmptyText(String text) Sets the text shown when there are no rows; empty by default.voidsetExpanded(int row, boolean open) Opens or closes a view row: a node of a tree, or a group.voidsetFilter(GridFilter filter) Shows only the rows a filter accepts; null shows them all.voidsetFrozenColumns(int count) Sets how many of the first visible columns stay in place while the rest scroll sideways; 0 by default.voidsetGridLines(boolean horizontal, boolean vertical) Sets which grid lines are drawn.voidGroups the rows by the values of a column, each group under a row of its own that opens and closes it; null stops grouping.voidsetHeaderVisible(boolean v) Shows or hides the header row.final voidsetModel(TableModel model) Shows the rows of a table model, with a column for each of its columns.final voidsetModel(TreeTableModel model) Shows the nodes of a tree table model, with a column for each of its columns.voidsetNodeExpanded(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.voidsetOverlayPainter(Painter painter) Sets a painter that draws over the cells and the headers, after everything else, as the outlines a spreadsheet draws around the cells a formula being edited refers to.voidsetRowHeightMM(float mm) Sets the height of a row in millimetres; 0, the default, fits the row style's font and padding.voidsetSelectedRow(int row) Selects one view row and moves the keyboard to it; -1 clears the selection.voidSets what a tap selects;MULTIPLE_ROWSby default.voidsetStriped(boolean striped) Sets whether every other row is painted inDataGridRowAlt.voidSets the column a tree grid draws the tree in; null, the default, is the first visible one.voidsetValueAt(int row, GridColumn c, Object value) Sets the value of a view row in a column, through the model.voidsortBy(GridColumn c, boolean ascending) Sorts by one column alone.protected voidtapped(int x, int y, boolean doubleTap) A tap that was not a drag or a long press.Methods inherited from class ScrollSurface
animate, animateSurface, applySettle, currentTime, getBodyHeight, getBodyWidth, getBodyX, getContentOriginX, getFadingHoverTarget, getHeaderHeight, getHeaderWidth, getHeaderX, getHoverLevel, getHoverTarget, getLiftLevel, getMaxOffsetX, getMaxOffsetY, getOffsetX, getOffsetY, getPageGrid, hasHoverFeedback, hoverGone, isBounded, isDragEdits, isEditInProgress, isPrinting, longPointerPress, longPressed, mouseWheel, paint, paintPage, pinch, pinchReleased, pointerDragged, pointerHover, pointerPressed, pointerReleased, refreshLayout, requestAnimation, restoreZoomState, saveZoomState, scrollTo, setAnimationTime, setBounded, setDragEdits, setHeaderSize, setHovered, setHoverTarget, setHoverTooltip, setOffsets, shouldBlockSideSwipe, startSettle, stopFling, zoomByMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyReleased, keyRepeated, laidOut, longKeyPress, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
DataGrid
public DataGrid()A grid with no data. -
DataGrid
A grid over the rows of a table model, with a column for each of its columns. -
DataGrid
A tree grid over a tree table model, with a column for each of its columns.
-
-
Method Details
-
setModel
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
Shows the nodes of a tree table model, with a column for each of its columns. The roots are shown closed. -
getTableModel
The table model shown, or null for a tree grid. -
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()Description copied from class:ComponentAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classScrollSurface
-
deinitialize
protected void deinitialize()Description copied from class:ComponentInvoked 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.- Overrides:
deinitializein classScrollSurface
-
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
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
The columns, in the order they are shown, hidden ones included. -
getColumnCount
public int getColumnCount()How many columns there are, hidden ones included. -
getColumn
The column at a place in the order, hidden ones counted. -
getColumnForModel
The column showing a column of the model, or null. -
setColumns
Replaces the columns. A model column with noGridColumnis not shown, and one may be shown twice. -
addColumn
Adds a column at the end. -
removeColumn
Removes a column. -
moveColumn
public void moveColumn(int from, int to) Moves the column atfromin the order toto, 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
The column a tree grid draws the tree in, or null for the first visible one. -
setTreeColumn
Sets the column a tree grid draws the tree in; null, the default, is the first visible one. -
sortBy
Sorts by one column alone. -
addSort
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
The columns sorted by, most significant first. -
getSortDirection
1 when sorted bycascending, -1 descending, 0 when not sorted by it. -
getFilter
The filter of the rows, or null. -
setFilter
Shows only the rows a filter accepts; null shows them all. -
getGroupColumn
The column the rows are grouped by, or null. -
setGroupColumn
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
The value a view row shows in a column. -
setValueAt
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
The node a view row of a tree grid shows, or null. -
getRowOfNode
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
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
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
What a tap selects. -
setSelectionMode
Sets what a tap selects;MULTIPLE_ROWSby 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 whenadd. -
selectAll
public void selectAll()Selects every row. -
clearSelection
public void clearSelection()Selects nothing. -
addSelectionListener
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
Stops listening to changes of the selection. -
addActionListener
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
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 inDataGridRowAlt. -
setStriped
public void setStriped(boolean striped) Sets whether every other row is painted inDataGridRowAlt. -
setGridLines
public void setGridLines(boolean horizontal, boolean vertical) Sets which grid lines are drawn. -
getEmptyText
The text shown when there are no rows. -
setEmptyText
Sets the text shown when there are no rows; empty by default. -
getDefaultRenderer
The renderer of a column that has none. -
setDefaultRenderer
Sets the renderer of a column that has none. -
getDefaultEditor
The editor of a column that has none. -
setDefaultEditor
Sets the editor of a column that has none. -
layoutSurface
protected void layoutSurface(int width, int height) Description copied from class:ScrollSurfaceLays 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.- Specified by:
layoutSurfacein classScrollSurface
-
isMirrored
protected boolean isMirrored()Right to left the grid is mirrored: the first column, and the frozen ones, are at the right, and it scrolls toward the left.- Overrides:
isMirroredin classScrollSurface
-
getContentWidth
protected int getContentWidth()Description copied from class:ScrollSurfaceThe width of what scrolls, in pixels, without the left header.- Specified by:
getContentWidthin classScrollSurface
-
getContentHeight
protected int getContentHeight()Description copied from class:ScrollSurfaceThe height of what scrolls, in pixels, without the top header.- Specified by:
getContentHeightin classScrollSurface
-
calcPreferredSize
Description copied from class:ComponentCalculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classScrollSurface
-
getPageStep
protected int getPageStep(int bodyHeight) Description copied from class:ScrollSurfaceHow far down a page of content heightbodyHeightgoes before the next one starts. A view of rows answers a whole number of them, so no page ends in the middle of one.- Overrides:
getPageStepin classScrollSurface
-
paintContent
Description copied from class:ScrollSurfacePaints what scrolls.xandyare 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.- Specified by:
paintContentin classScrollSurface
-
paintLeftHeader
Description copied from class:ScrollSurfacePaints the pinned left column.xis its left;yis where the content's origin is.- Overrides:
paintLeftHeaderin classScrollSurface
-
paintTopHeader
Description copied from class:ScrollSurfacePaints the pinned top row.xis where the content's origin is;yis the top of the row.- Overrides:
paintTopHeaderin classScrollSurface
-
paintCorner
Description copied from class:ScrollSurfacePaints the corner where the two headers meet, at its top left.- Overrides:
paintCornerin classScrollSurface
-
paintOverlay
Description copied from class:ScrollSurfacePaints over everything, in the component's own bounds, whose top left isx,y. Not painted on a printed page: it is for what a gesture in progress shows.- Overrides:
paintOverlayin classScrollSurface
-
setCellPicker
Sets what takes the taps on cells while it asks for them, as the formula editor of a spreadsheet does to put the tapped cell's reference into a formula. Null, the default, leaves every tap to the grid.
Parameters
picker: the picker, or null
-
getCellPicker
The picker set with
#setCellPicker(GridCellPicker).Returns
the picker, or null
-
setOverlayPainter
Sets a painter that draws over the cells and the headers, after everything else, as the outlines a spreadsheet draws around the cells a formula being edited refers to. The rectangle it is given is the grid's, in the coordinates it paints in, so a cell is at the rectangle's corner plus what
#getCellBounds(int, int, int[])answers. Null, the default, draws nothing;repaint()after what it draws changes.Parameters
painter: the painter, or null
-
getOverlayPainter
The painter set with
#setOverlayPainter(com.codename1.ui.Painter).Returns
the painter, or null
-
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.columnis an index among the visible columns. -
getVisibleColumns
The columns shown, in order: the onesgetSelectedColumn()andgetCellBoundscount. -
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) Description copied from class:ScrollSurfaceThe pointer went down at a point, in the component's coordinates. Whatever it turns into -- a tap, a drag, a long press -- follows.- Overrides:
pressStartedin classScrollSurface
-
tapped
protected void tapped(int x, int y, boolean doubleTap) Description copied from class:ScrollSurfaceA tap that was not a drag or a long press.- Overrides:
tappedin classScrollSurface
-
editStarted
Description copied from class:ScrollSurfaceAsked when a drag or a long press begins, at the point where the pointer went down, in the component's coordinates.
Parameters
trigger: what kind of gesture it is
Returns
true when an edit has begun and the drag belongs to it; false to pan
- Overrides:
editStartedin classScrollSurface
-
editMoved
protected void editMoved(int x, int y) Description copied from class:ScrollSurfaceThe pointer of an edit moved, or the surface scrolled under it.- Overrides:
editMovedin classScrollSurface
-
editEnded
protected void editEnded(boolean committed) Description copied from class:ScrollSurfaceThe edit is over.committedis false when it was cancelled: bycancelEdit, a second finger, or the surface leaving the form.- Overrides:
editEndedin classScrollSurface
-
isEditAutoScroll
protected boolean isEditAutoScroll(int x, int y) Description copied from class:ScrollSurfaceWhether the surface scrolls under an edit dragged near its edge. Asked on every move of an edit; true by default.- Overrides:
isEditAutoScrollin classScrollSurface
-
hoverAt
protected void hoverAt(int x, int y) Description copied from class:ScrollSurfaceThe pointer rests at a point of the surface without being pressed. A view answers withsetHoverTarget, naming what is there and the cursor that says what a press would do.- Overrides:
hoverAtin classScrollSurface
-
scrollChanged
protected void scrollChanged()Description copied from class:ScrollSurfaceThe scroll position changed.- Overrides:
scrollChangedin classScrollSurface
-
handlesInput
public boolean handlesInput()Description copied from class:ComponentPrevents 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
- Overrides:
handlesInputin classComponent- Returns:
- true if key events are being used for focus traversal ; otherwise false
-
keyPressed
public void keyPressed(int keyCode) Description copied from class:ComponentIf this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classComponent
-
isEditing
-
getEditingRow
public int getEditingRow()The view row being edited, or -1. -
getEditingColumn
The column being edited, or null. -
editCellAt
public boolean editCellAt(int row, int column) Edits a cell, when it may be edited.
columnis 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.- Overrides:
cancelEditin classScrollSurface
-