V
- Type of data to store in the table cells, presented through toString()
Component
, Interactable
, TextGUIElement
public class Table<V> extends AbstractInteractableComponent<Table<V>>
Interactable.FocusChangeDirection, Interactable.Result
Constructor | Description |
---|---|
Table(String... columnLabels) |
Creates a new
Table with the number of columns as specified by the array of labels |
Modifier and Type | Method | Description |
---|---|---|
protected TableRenderer<V> |
createDefaultRenderer() |
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).
|
TableRenderer<V> |
getRenderer() |
Returns the renderer used to draw this component and measure its preferred size.
|
int |
getSelectedColumn() |
Returns the currently selection column index, if in cell-selection mode.
|
int |
getSelectedRow() |
Returns the index of the currently selected row
|
TableCellRenderer<V> |
getTableCellRenderer() |
Returns the
TableCellRenderer used by this table when drawing cells |
TableHeaderRenderer<V> |
getTableHeaderRenderer() |
Returns the
TableHeaderRenderer used by this table when drawing the table's header |
TableModel<V> |
getTableModel() |
Returns the underlying table model
|
int |
getViewLeftColumn() |
Returns the index of the column that is currently the first column visible.
|
int |
getViewTopRow() |
Returns the index of the row that is currently the first row visible.
|
int |
getVisibleColumns() |
Returns the number of columns this table will show.
|
int |
getVisibleRows() |
Returns the number of rows this table will show.
|
Interactable.Result |
handleKeyStroke(KeyStroke keyStroke) |
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in
focus.
|
boolean |
isCellSelection() |
Returns
true if this table is in cell-selection mode, otherwise false |
boolean |
isEscapeByArrowKey() |
Returns
true 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. |
Table<V> |
setCellSelection(boolean cellSelection) |
If
true , the user will be able to select and navigate individual cells, otherwise the user can only
select full rows. |
Table<V> |
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.
|
Table<V> |
setSelectAction(Runnable selectAction) |
Assigns an action to run whenever the user presses the enter key while focused on the table.
|
Table<V> |
setSelectedColumn(int selectedColumn) |
If in cell selection mode, updates which column is selected and ensures the selected column is visible in the
view.
|
Table<V> |
setSelectedRow(int selectedRow) |
Sets the index of the selected row and ensures the selected row is visible in the view
|
Table<V> |
setTableCellRenderer(TableCellRenderer<V> tableCellRenderer) |
Replaces the
TableCellRenderer used by this table when drawing cells |
Table<V> |
setTableHeaderRenderer(TableHeaderRenderer<V> tableHeaderRenderer) |
Replaces the
TableHeaderRenderer used by this table when drawing the table's header |
Table<V> |
setTableModel(TableModel<V> tableModel) |
Updates the table with a new table model, effectively replacing the content of the table completely
|
Table<V> |
setViewLeftColumn(int viewLeftColumn) |
Sets the view column offset for the first column to display in the table.
|
Table<V> |
setViewTopRow(int viewTopRow) |
Sets the view row offset for the first row to display in the table.
|
void |
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.
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
afterEnterFocus, afterLeaveFocus, getCursorLocation, getInputFilter, handleInput, isEnabled, isFocusable, isFocused, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
addTo, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, toBasePane, toGlobal, withBorder
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
draw, isInvalid
public Table(String... columnLabels)
Table
with the number of columns as specified by the array of labelscolumnLabels
- Creates one column per label in the array, must be more than onepublic TableModel<V> getTableModel()
public Table<V> setTableModel(TableModel<V> tableModel)
tableModel
- New table modelpublic TableCellRenderer<V> getTableCellRenderer()
TableCellRenderer
used by this table when drawing cellsTableCellRenderer
used by this table when drawing cellspublic Table<V> setTableCellRenderer(TableCellRenderer<V> tableCellRenderer)
TableCellRenderer
used by this table when drawing cellstableCellRenderer
- New TableCellRenderer
to usepublic TableHeaderRenderer<V> getTableHeaderRenderer()
TableHeaderRenderer
used by this table when drawing the table's headerTableHeaderRenderer
used by this table when drawing the table's headerpublic Table<V> setTableHeaderRenderer(TableHeaderRenderer<V> tableHeaderRenderer)
TableHeaderRenderer
used by this table when drawing the table's headertableHeaderRenderer
- New TableHeaderRenderer
to usepublic void setVisibleColumns(int visibleColumns)
visibleColumns
- Number of columns to display at oncepublic int getVisibleColumns()
public void setVisibleRows(int visibleRows)
visibleRows
- Number of rows to display at oncepublic int getVisibleRows()
public int getViewTopRow()
setViewTopRow(..)
) has scrolled down.public Table<V> setViewTopRow(int viewTopRow)
viewTopRow
- Index of the row that is currently the first row visiblepublic int getViewLeftColumn()
setViewLeftColumn(..)
) has scrolled to the
right.public Table<V> setViewLeftColumn(int viewLeftColumn)
viewLeftColumn
- Index of the column that is currently the first column visiblepublic int getSelectedColumn()
public Table<V> setSelectedColumn(int selectedColumn)
selectedColumn
- Index of the column that should be selectedpublic int getSelectedRow()
public Table<V> setSelectedRow(int selectedRow)
selectedRow
- Index of the row to selectpublic Table<V> setCellSelection(boolean cellSelection)
true
, the user will be able to select and navigate individual cells, otherwise the user can only
select full rows.cellSelection
- true
if cell selection should be enabled, false
for row selectionpublic boolean isCellSelection()
true
if this table is in cell-selection mode, otherwise false
true
if this table is in cell-selection mode, otherwise false
public Table<V> setSelectAction(Runnable selectAction)
null
, no action will be run.selectAction
- Action to perform when user presses the enter keypublic boolean isEscapeByArrowKey()
true
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. With escapeByArrowKey
set to true
,
this will move focus away from the table in the direction the user pressed, if false
then nothing will
happen.true
if user can switch focus away from the table using arrow keys, false
otherwisepublic Table<V> setEscapeByArrowKey(boolean escapeByArrowKey)
escapeByArrowKey
set to true
,
this will move focus away from the table in the direction the user pressed, if false
then nothing will
happen.escapeByArrowKey
- true
if user can switch focus away from the table using arrow keys, false
otherwiseprotected TableRenderer<V> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractInteractableComponent<Table<V>>
public TableRenderer<V> getRenderer()
Component
getRenderer
in interface Component
getRenderer
in class AbstractInteractableComponent<Table<V>>
public Interactable.Result handleKeyStroke(KeyStroke keyStroke)
AbstractInteractableComponent
handleInput(..)
is final in
AbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that
this event should be processed, it will call this method.handleKeyStroke
in class AbstractInteractableComponent<Table<V>>
keyStroke
- What input was entered by the userCopyright © 2020. All rights reserved.