java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<Table<V>>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<Table<V>>
com.googlecode.lanterna.gui2.table.Table<V>
- Type Parameters:
V
- Type of data to store in the table cells, presented throughtoString()
- All Implemented Interfaces:
Component
,Interactable
,TextGUIElement
The table class is an interactable component that displays a grid of cells containing data along with a header of
labels. It supports scrolling when the number of rows and/or columns gets too large to fit and also supports
user selection which is either row-based or cell-based. User will move the current selection by using the arrow keys
on the keyboard.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.Interactable
Interactable.FocusChangeDirection, Interactable.Result
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private Runnable
private int
private int
private TableCellRenderer
<V> private TableHeaderRenderer
<V> private TableModel
<V> private TableModel.Listener
<V> private int
private int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected TableRenderer
<V> When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).protected int
getColumnByMouseAction
(MouseAction mouseAction) By convertingTerminalPosition
s toAbstractComponent.toGlobal(TerminalPosition)
and by comparing widths of column headers, gets column clicked on by mouse action.int
Returns the index of the first row that is currently visible.int
Returns the index of the last row that is currently visible.Returns the renderer used to draw this component and measure its preferred size.protected int
getRowByMouseAction
(MouseAction mouseAction) By convertingTerminalPosition
s toAbstractComponent.toGlobal(TerminalPosition)
gets row clicked on by mouse action.int
Returns the currently selection column index, if in cell-selection mode.int
Returns the index of the currently selected rowReturns theTableCellRenderer
used by this table when drawing cellsReturns theTableHeaderRenderer
used by this table when drawing the table's headerReturns the underlying table modelint
Deprecated.Use the table renderers method insteadint
Deprecated.Use the table renderers method insteadint
Returns the number of columns this table will show.int
Returns the number of rows this table will show.handleKeyStroke
(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.boolean
Returnstrue
if this table is in cell-selection mode, otherwisefalse
boolean
Returnstrue
if this table can be navigated away from when the selected row is at one of the extremes and the user presses the array key to continue in that direction.setCellSelection
(boolean cellSelection) Iftrue
, the user will be able to select and navigate individual cells, otherwise the user can only select full rows.setEscapeByArrowKey
(boolean escapeByArrowKey) Sets the flag for if this table can be navigated away from when the selected row is at one of the extremes and the user presses the array key to continue in that direction.setSelectAction
(Runnable selectAction) Assigns an action to run whenever the user presses the enter or space key while focused on the table.setSelectedColumn
(int selectedColumn) If in cell selection mode, updates which column is selected and ensures the selected column is visible in the view.setSelectedRow
(int selectedRow) Sets the index of the selected row and ensures the selected row is visible in the viewsetTableCellRenderer
(TableCellRenderer<V> tableCellRenderer) Replaces theTableCellRenderer
used by this table when drawing cellssetTableHeaderRenderer
(TableHeaderRenderer<V> tableHeaderRenderer) Replaces theTableHeaderRenderer
used by this table when drawing the table's headersetTableModel
(TableModel<V> tableModel) Updates the table with a new table model, effectively replacing the content of the table completelysetViewLeftColumn
(int viewLeftColumn) Deprecated.Use the table renderers method insteadsetViewTopRow
(int viewTopRow) Deprecated.Use the table renderers method insteadvoid
setVisibleColumns
(int visibleColumns) Sets the number of columns this table should show.void
setVisibleRows
(int visibleRows) Sets the number of rows this table will show.Methods inherited from class com.googlecode.lanterna.gui2.AbstractInteractableComponent
afterEnterFocus, afterLeaveFocus, getCursorLocation, getInputFilter, handleInput, isActivationStroke, isEnabled, isFocusable, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.googlecode.lanterna.gui2.Component
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIElement
draw, isInvalid
-
Field Details
-
tableModel
-
tableModelListener
-
tableHeaderRenderer
-
tableCellRenderer
-
selectAction
-
cellSelection
private boolean cellSelection -
visibleRows
private int visibleRows -
visibleColumns
private int visibleColumns -
selectedRow
private int selectedRow -
selectedColumn
private int selectedColumn -
escapeByArrowKey
private boolean escapeByArrowKey
-
-
Constructor Details
-
Table
Creates a newTable
with the number of columns as specified by the array of labels- Parameters:
columnLabels
- Creates one column per label in the array, must be more than one
-
-
Method Details
-
getTableModel
Returns the underlying table model- Returns:
- Underlying table model
-
setTableModel
Updates the table with a new table model, effectively replacing the content of the table completely- Parameters:
tableModel
- New table model- Returns:
- Itself
-
getTableCellRenderer
Returns theTableCellRenderer
used by this table when drawing cells- Returns:
TableCellRenderer
used by this table when drawing cells
-
setTableCellRenderer
Replaces theTableCellRenderer
used by this table when drawing cells- Parameters:
tableCellRenderer
- NewTableCellRenderer
to use- Returns:
- Itself
-
getTableHeaderRenderer
Returns theTableHeaderRenderer
used by this table when drawing the table's header- Returns:
TableHeaderRenderer
used by this table when drawing the table's header
-
setTableHeaderRenderer
Replaces theTableHeaderRenderer
used by this table when drawing the table's header- Parameters:
tableHeaderRenderer
- NewTableHeaderRenderer
to use- Returns:
- Itself
-
setVisibleColumns
public void setVisibleColumns(int visibleColumns) Sets the number of columns this table should show. If there are more columns in the table model, a scrollbar will be used to allow the user to scroll left and right and view all columns.- Parameters:
visibleColumns
- Number of columns to display at once
-
getVisibleColumns
public int getVisibleColumns()Returns the number of columns this table will show. If there are more columns in the table model, a scrollbar will be used to allow the user to scroll left and right and view all columns.- Returns:
- Number of visible columns for this table
-
setVisibleRows
public void setVisibleRows(int visibleRows) Sets the number of rows this table will show. If there are more rows in the table model, a scrollbar will be used to allow the user to scroll up and down and view all rows.- Parameters:
visibleRows
- Number of rows to display at once
-
getVisibleRows
public int getVisibleRows()Returns the number of rows this table will show. If there are more rows in the table model, a scrollbar will be used to allow the user to scroll up and down and view all rows.- Returns:
- Number of rows to display at once
-
getViewTopRow
Deprecated.Use the table renderers method insteadReturns the index of the row that is currently the first row visible. This is always 0 unless scrolling has been enabled and either the user or the software (throughsetViewTopRow(..)
) has scrolled down.- Returns:
- Index of the row that is currently the first row visible
-
getFirstViewedRowIndex
public int getFirstViewedRowIndex()Returns the index of the first row that is currently visible.- Returns:
- the index of the first row that is currently visible
-
getLastViewedRowIndex
public int getLastViewedRowIndex()Returns the index of the last row that is currently visible.- Returns:
- the index of the last row that is currently visible
-
setViewTopRow
Deprecated.Use the table renderers method insteadSets the view row offset for the first row to display in the table. Calling this with 0 will make the first row in the model be the first visible row in the table.- Parameters:
viewTopRow
- Index of the row that is currently the first row visible- Returns:
- Itself
-
getViewLeftColumn
Deprecated.Use the table renderers method insteadReturns the index of the column that is currently the first column visible. This is always 0 unless scrolling has been enabled and either the user or the software (throughsetViewLeftColumn(..)
) has scrolled to the right.- Returns:
- Index of the column that is currently the first column visible
-
setViewLeftColumn
Deprecated.Use the table renderers method insteadSets the view column offset for the first column to display in the table. Calling this with 0 will make the first column in the model be the first visible column in the table.- Parameters:
viewLeftColumn
- Index of the column that is currently the first column visible- Returns:
- Itself
-
getSelectedColumn
public int getSelectedColumn()Returns the currently selection column index, if in cell-selection mode. Otherwise it returns -1.- Returns:
- In cell-selection mode returns the index of the selected column, otherwise -1
-
setSelectedColumn
If in cell selection mode, updates which column is selected and ensures the selected column is visible in the view. If not in cell selection mode, does nothing.- Parameters:
selectedColumn
- Index of the column that should be selected- Returns:
- Itself
-
getSelectedRow
public int getSelectedRow()Returns the index of the currently selected row- Returns:
- Index of the currently selected row
-
setSelectedRow
Sets the index of the selected row and ensures the selected row is visible in the view- Parameters:
selectedRow
- Index of the row to select- Returns:
- Itself
-
setCellSelection
Iftrue
, the user will be able to select and navigate individual cells, otherwise the user can only select full rows.- Parameters:
cellSelection
-true
if cell selection should be enabled,false
for row selection- Returns:
- Itself
-
isCellSelection
public boolean isCellSelection()Returnstrue
if this table is in cell-selection mode, otherwisefalse
- Returns:
true
if this table is in cell-selection mode, otherwisefalse
-
setSelectAction
Assigns an action to run whenever the user presses the enter or space key while focused on the table. If called withnull
, no action will be run.- Parameters:
selectAction
- Action to perform when user presses the enter or space key- Returns:
- Itself
-
isEscapeByArrowKey
public boolean isEscapeByArrowKey()Returnstrue
if this table can be navigated away from when the selected row is at one of the extremes and the user presses the array key to continue in that direction. WithescapeByArrowKey
set totrue
, this will move focus away from the table in the direction the user pressed, iffalse
then nothing will happen.- Returns:
true
if user can switch focus away from the table using arrow keys,false
otherwise
-
setEscapeByArrowKey
Sets the flag for if this table can be navigated away from when the selected row is at one of the extremes and the user presses the array key to continue in that direction. WithescapeByArrowKey
set totrue
, this will move focus away from the table in the direction the user pressed, iffalse
then nothing will happen.- Parameters:
escapeByArrowKey
-true
if user can switch focus away from the table using arrow keys,false
otherwise- Returns:
- Itself
-
createDefaultRenderer
Description copied from class:AbstractComponent
When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRenderer
in classAbstractInteractableComponent<Table<V>>
- Returns:
- Renderer to use when sizing and drawing this component
-
getRenderer
Description copied from interface:Component
Returns the renderer used to draw this component and measure its preferred size. You probably won't need to call this method unless you know exactly which ComponentRenderer implementation is used and you need to customize it.- Specified by:
getRenderer
in interfaceComponent
- Overrides:
getRenderer
in classAbstractInteractableComponent<Table<V>>
- Returns:
- Renderer this component is using
-
handleKeyStroke
Description copied from class:AbstractInteractableComponent
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface,handleInput(..)
is final inAbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Overrides:
handleKeyStroke
in classAbstractInteractableComponent<Table<V>>
- Parameters:
keyStroke
- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
getRowByMouseAction
By convertingTerminalPosition
s toAbstractComponent.toGlobal(TerminalPosition)
gets row clicked on by mouse action.- Returns:
- row of a table that was clicked on with
MouseAction
-
getColumnByMouseAction
By convertingTerminalPosition
s toAbstractComponent.toGlobal(TerminalPosition)
and by comparing widths of column headers, gets column clicked on by mouse action.- Returns:
- row of a table that was clicked on with
MouseAction
-