Package jltk.gui
Class Table
- java.lang.Object
-
- jltk.Component
-
- jltk.gui.Control
-
- jltk.gui.Table
-
public class Table extends Control
A table events: cellselected, cellEdited, contentChanged- Version:
- 27.05.2022
- Author:
- ms
-
-
Field Summary
Fields Modifier and Type Field Description protected javafx.scene.control.TableView<ArrayList<String>>
fxTableView
(package private) ArrayList<String>
line1
(package private) ArrayList<String>
line2
-
Fields inherited from class jltk.Component
fxNode, hasFocus, myWindow, onFocusGained, onFocusLost
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendColumn(String pTitle)
Appends a column to the end of this table.void
appendColumn(String pTitle, Object[] pContent)
Appends a column with the specified content to the end of this table. pContent must be an array of any kind of objects.void
appendRow()
Appends a empty row to the end of this table.void
appendRow(Object[] pContent)
Inserts a row with the specified content to the end of this table.void
autosize()
Increases or decreases the the width of each cell to fit all cells into the visible part of the table.void
clearAll()
Clears the table.void
clearData()
Removes all data from the table.void
createColumns(int pNumber)
Removes all columns and data and creates the specified number of columns.void
createColumns(String[] pTitles)
Removes all columns and data and creates new columns with the specified title.void
deselect(int pRow)
Deselects the specified row.void
deselect(int pRow, int pColumn)
Deselects the specified cell.void
deselectAll()
Removes every selection.void
disableEditable()
Makes the table read-onlyvoid
disableSelection()
Disables selection of cells an rows.void
enableCellSelection()
Enables selection of single cells.void
enableEditable()
void
enableEditable(int pRow)
Makes the specified row of this table editable.void
enableMultiSelection()
Enables multi selection of rows or cells.void
enableRowSelection()
Enables selection of single rows.void
enableSingleSelection()
Enables single selection of rows or cells (only one selection per at the same time).String[]
getColumn(int pIndex)
Returns the specified column as string array.int
getColumnCount()
Returns the number of columns of this table.String
getItem(int pRow, int pColumn)
Returns the element at the specified position in this table.String[][]
getItems()
Returns all items of the table as 2d string array.String[]
getRow(int pIndex)
Returns the specified row as string array.int
getRowCount()
Returns the number of rows of this table.int[][]
getSelectedCellsIndices()
Returns the indices of all selected cells.String[]
getSelectedColumn()
int
getSelectedColumnIndex()
Returns the index of the selected column and -1, if there is no selection.String[][]
getSelectedColumns()
int[]
getSelectedColumnsIndices()
String
getSelectedItem()
String[]
getSelectedItems()
String[]
getSelectedRow()
Returns the currently selected row as string array.int
getSelectedRowIndex()
Returns the index of the selected row and -1, if there is no selection.String[][]
getSelectedRows()
Returns returns the currently selected rows as 2-d string array.int[]
getSelectedRowsIndices()
Returns an int array containing the indices of all selected rows.void
insertColumn(int pIndex, String pTitle)
Inserts a empty column at the specified position of this table.void
insertColumn(int pIndex, String pTitle, Object[] pContent)
Inserts a column with specified content at the specified position of this table.void
insertRow(int pIndex)
Inserts a row with the specified content at the specified position in this table.void
insertRow(int pIndex, Object[] pContent)
Inserts a row with the specified content at the specified position in this table.boolean
isSelected(int pRow)
Returns true, if the specified row currently is selected.boolean
isSelected(int pRow, int pColumn)
Returns true, if the specified cell is selected or not.void
refresh()
Refresh/Rebuild the table.void
removeColumn(int pIndex)
Removes the column at the specified position of this table.void
removeRow(int pIndex)
Removes the row at the specified position of this table.void
select(int pRow)
Selects the specified rowvoid
select(int pRow, int pColumn)
Selects the specified cell.void
selectAll()
Selects all cells.void
setColumnTitle(int pIndex, String pTitle)
Sets the title of the specified column.void
setColumnWidth(int pWidth)
Set the width of every column to the specified width in pixel.void
setColumnWidth(int pIndex, int pWidth)
Set the width of the specified column to the specified width in pixel.void
setItem(int pRow, int pColumn, String pText)
Replaces the item at the specified postion in this table.void
setItems(Object[][] pContent)
Sets the specified content as new content for the tables.void
setItems(Object[][] pContent, String[] pTitles)
Sets the specified content as new content for the tables. pTitles specifies the column title.void
setOnCellEdited(String pMethodName)
Sets the name of the method, which should be invoke, if a cell was edited.void
setOnCellSelected(String pMethodName)
Sets the name of the method, which should be invoke, if a selection was made.void
setOnContentChanged(String pMethodName)
Sets the name of the method, which should be invoke, if the table data where changed.void
test(String neu)
-
Methods inherited from class jltk.gui.Control
getColor, getHeight, getWidth, init, setColor, setColor, setColor, setHeight, setSize, setTooltip, setWidth
-
Methods inherited from class jltk.Component
activate, deactivate, focus, getX, getY, hasFocus, hide, init, istActive, isVisible, runMethodByName, setOnFocusGained, setOnFocusLost, setPosition, show, toBack, toFront
-
-
-
-
Constructor Detail
-
Table
public Table(double pLeft, double pTop, double pWidth, double pHeight)
Create the Table on the main View- Parameters:
pLeft
- The horizontal coordinatepTop
- The vertical coordinatepWidth
- The width of the combo boxpHeight
- The height of the combo box
-
Table
public Table(Window pWindow, double pLeft, double pTop, double pWidth, double pHeight)
Creates the Table- Parameters:
pLeft
- The horizontal coordinatepTop
- The vertical coordinatepWidth
- The width of the tablepHeight
- The height of the tablepWindow
- The window, the table should be placed
-
-
Method Detail
-
test
public void test(String neu)
-
appendColumn
public void appendColumn(String pTitle)
Appends a column to the end of this table. If the underlying data still hold data for this column, this data will be shown. If not, the column will be empty- Parameters:
pTitle
- The title of the new column
-
appendColumn
public void appendColumn(String pTitle, Object[] pContent)
Appends a column with the specified content to the end of this table. pContent must be an array of any kind of objects. The string representation (.toString()) of each object will be used. If the underlying data still hold data for this column, they will be overwritten by the new data.- Parameters:
pTitle
- The title of the new columnpContent
- The content of the new column
-
insertColumn
public void insertColumn(int pIndex, String pTitle)
Inserts a empty column at the specified position of this table. Shifts the column currently at this position and any subsequent columns to the right. The index of the first column is 0.- Parameters:
pIndex
- The position of the new column (first column has index 0)pTitle
- The title of the new column
-
insertColumn
public void insertColumn(int pIndex, String pTitle, Object[] pContent)
Inserts a column with specified content at the specified position of this table. Shifts the column currently at this position and any subsequent columns to the right.pContent must be an array of any kind of objects. The string representation (.toString()) of each object will be used. The index of the first column is 0.- Parameters:
pIndex
- The position of the new column (first column has index 0)pTitle
- The title of the new columnpContent
- The content of the new column
-
removeColumn
public void removeColumn(int pIndex)
Removes the column at the specified position of this table. Any subsequent columns shift to the left. The index of the first column is 0- Parameters:
pIndex
- The position of the new column (first column has index 0)
-
appendRow
public void appendRow()
Appends a empty row to the end of this table.
-
appendRow
public void appendRow(Object[] pContent)
Inserts a row with the specified content to the end of this table.- Parameters:
pContent
- The content for the new row
-
insertRow
public void insertRow(int pIndex, Object[] pContent)
Inserts a row with the specified content at the specified position in this table. Shifts the row currently at this position and any subsequent rows to the right. The index of the first row is 0.- Parameters:
pIndex
- The position of the new row (first column has index 0)
-
insertRow
public void insertRow(int pIndex)
Inserts a row with the specified content at the specified position in this table. Shifts the row currently at this position and any subsequent rows to the right. The index of the first row is 0.- Parameters:
pIndex
- The position of the new row (first column has index 0)
-
removeRow
public void removeRow(int pIndex)
Removes the row at the specified position of this table. Any subsequent row shift to the left. The index of the first row is 0- Parameters:
pIndex
- The position of the new row (first row has index 0)
-
createColumns
public void createColumns(String[] pTitles)
Removes all columns and data and creates new columns with the specified title.- Parameters:
pTitles
- The titles of the new columns
-
setColumnTitle
public void setColumnTitle(int pIndex, String pTitle)
Sets the title of the specified column.- Parameters:
pIndex
- The index of the column (First column has index 0)pTitle
- The new title.
-
createColumns
public void createColumns(int pNumber)
Removes all columns and data and creates the specified number of columns. The column title will be set to A,B,C,...- Parameters:
pQuantity
- The nummber of new columns.
-
setItems
public void setItems(Object[][] pContent, String[] pTitles)
Sets the specified content as new content for the tables. pTitles specifies the column title. If the length of pTitles is smaller than the number of data columns, empty columns will be append, If the length of pTitles is greater than the number of data columns, the colums will be titled with chars.- Parameters:
pContent
- The new content of the tablepContent
- The new title of the table columns
-
setItems
public void setItems(Object[][] pContent)
Sets the specified content as new content for the tables. The column title will be automatically set to A,B,C,...- Parameters:
pContent
- the new content of the table.
-
refresh
public void refresh()
Refresh/Rebuild the table.
-
clearAll
public void clearAll()
Clears the table. Deletes all data and all headers.
-
clearData
public void clearData()
Removes all data from the table. Do not clear the headers.
-
setItem
public void setItem(int pRow, int pColumn, String pText)
Replaces the item at the specified postion in this table.- Parameters:
pRow
- The index of the row (starting with 0).pColumn
- The index of the column (starting with 0).pText
- The string to be inserted
-
getRowCount
public int getRowCount()
Returns the number of rows of this table.- Returns:
- The number of rows.
-
getColumnCount
public int getColumnCount()
Returns the number of columns of this table.- Returns:
- The number of columns.
-
getItem
public String getItem(int pRow, int pColumn)
Returns the element at the specified position in this table. If the cell does not exists, null will be returned.- Parameters:
pRow
- The index of the row (starting with 0).pColumn
- The index of the column (starting with 0).- Returns:
- The element at the specified position in this table. null, if not exists.
-
getItems
public String[][] getItems()
Returns all items of the table as 2d string array.- Returns:
- all items of the table.
-
getRow
public String[] getRow(int pIndex)
Returns the specified row as string array. If the row does not exists, null will be returned The first row has the index 0.- Parameters:
pRow
- The index of the row (starting with 0).- Returns:
- The specified row as string array. null, if not exists.
-
getColumn
public String[] getColumn(int pIndex)
Returns the specified column as string array. If the column does not exists, null will be returned The first column has the index 0.- Parameters:
pColumn
- The index of the column (starting with 0).- Returns:
- The specified row as string array. null, if not exists.
-
getSelectedRowIndex
public int getSelectedRowIndex()
Returns the index of the selected row and -1, if there is no selection. If multi-selection is enabled, the lowest index is returned. You can use getSelectedRowIndices() to get all selected indices if you enabled multi-selection.- Returns:
- The index of the selected row.
-
getSelectedColumnIndex
public int getSelectedColumnIndex()
Returns the index of the selected column and -1, if there is no selection. If multiple columns are selected, the lowest index of that column, which is selected in the row with the lowest index is returned. Especially this means, you always get 0, if row selection is enabled. If you enabled multi-selection, you can use getSelectedCellIndices() to get all indices of the selected cells.- Returns:
- The index of the selected column.
-
getSelectedColumnsIndices
public int[] getSelectedColumnsIndices()
-
getSelectedRowsIndices
public int[] getSelectedRowsIndices()
Returns an int array containing the indices of all selected rows.- Returns:
- The indices of the selected rows.
-
getSelectedCellsIndices
public int[][] getSelectedCellsIndices()
Returns the indices of all selected cells. It is an nx2 int-array. Each line of the array holds the row index and the column index of a cell. E.g. if arr is the array, arr[3][0] describes the row index of the fourth selected cell and arr[10][1] describes the column index of the eleventh selected cell.- Returns:
- The indices of all selected cell.
-
getSelectedRow
public String[] getSelectedRow()
Returns the currently selected row as string array. If ther is no selection, an empty array (length is 0) will be returned. If multi-selection is enabled, the the row with the lowest index is returned. You can use getSelectedRows() to get all selected rows, if you enabled multi-selection.- Returns:
- The selected row as string array.
-
getSelectedRows
public String[][] getSelectedRows()
Returns returns the currently selected rows as 2-d string array. The first element (array[0]) represents the first selected row, the second element (array[1]), represents the second selected row, and so on. The array is empty (length = 0) if there is no selection.- Returns:
- The selected rows as 2-d string array.
-
getSelectedColumn
public String[] getSelectedColumn()
-
getSelectedColumns
public String[][] getSelectedColumns()
-
getSelectedItems
public String[] getSelectedItems()
-
getSelectedItem
public String getSelectedItem()
-
isSelected
public boolean isSelected(int pRow, int pColumn)
Returns true, if the specified cell is selected or not. If row selection is enabled, it will return true, if the specified row is selected, no matter what pColumn is.- Parameters:
pRow
- Ein ParameterpColumn
- Ein Parameter- Returns:
- Der Rückgabewert
-
isSelected
public boolean isSelected(int pRow)
Returns true, if the specified row currently is selected.- Parameters:
pRow
- The index of the row (first row has index 0)- Returns:
- true, if the row is selected.
-
setColumnWidth
public void setColumnWidth(int pIndex, int pWidth)
Set the width of the specified column to the specified width in pixel.- Parameters:
pIndex
- The index of the row (starting with 0).pWidth
- The new width of the row in pixel.
-
setColumnWidth
public void setColumnWidth(int pWidth)
Set the width of every column to the specified width in pixel.- Parameters:
pWidth
- The new width for every row in pixel.
-
autosize
public void autosize()
Increases or decreases the the width of each cell to fit all cells into the visible part of the table.
-
select
public void select(int pRow)
Selects the specified row- Parameters:
pRow
- The index of the row (first row has index 0).
-
select
public void select(int pRow, int pColumn)
Selects the specified cell.- Parameters:
pRow
- The index of the row (first row has index 0).pColumn
- The index of the column (first column has index 0).
-
selectAll
public void selectAll()
Selects all cells. This only works, if multi-selection is enabled (.enableMultiSelection())
-
deselect
public void deselect(int pRow)
Deselects the specified row.- Parameters:
pRow
- The index of the row (first row has index 0)
-
deselect
public void deselect(int pRow, int pColumn)
Deselects the specified cell.- Parameters:
pRow
- The index of the row (first row has index 0).pColumn
- The index of the column (first column has index 0).
-
deselectAll
public void deselectAll()
Removes every selection.
-
disableSelection
public void disableSelection()
Disables selection of cells an rows. To enable selection use enableCellSelection() or enableRowSelection() to enable selction.
-
enableCellSelection
public void enableCellSelection()
Enables selection of single cells. You can use enabelMultiSelect() to enable selecting of multiple cell.
-
enableRowSelection
public void enableRowSelection()
Enables selection of single rows. You can use enabelMultiSelect() to enable selecting of multiple cell.
-
enableMultiSelection
public void enableMultiSelection()
Enables multi selection of rows or cells. Depending if row or cell-selection is enabled (see enableCellSelection() and enableRowSelection())
-
enableSingleSelection
public void enableSingleSelection()
Enables single selection of rows or cells (only one selection per at the same time). Depending if row or cell-selection is enabled (see enableCellSelection() and enableRowSelection())
-
enableEditable
public void enableEditable(int pRow)
Makes the specified row of this table editable.
-
enableEditable
public void enableEditable()
-
disableEditable
public void disableEditable()
Makes the table read-only
-
setOnCellSelected
public void setOnCellSelected(String pMethodName)
Sets the name of the method, which should be invoke, if a selection was made.
-
setOnCellEdited
public void setOnCellEdited(String pMethodName)
Sets the name of the method, which should be invoke, if a cell was edited.
-
setOnContentChanged
public void setOnContentChanged(String pMethodName)
Sets the name of the method, which should be invoke, if the table data where changed.
-
-