Package jltk.gui

Class Table


  • public class Table
    extends Control
    A table events: cellselected, cellEdited, contentChanged
    Version:
    27.05.2022
    Author:
    ms
    • Constructor Detail

      • Table

        public Table​(double pLeft,
                     double pTop,
                     double pWidth,
                     double pHeight)
        Create the Table on the main View
        Parameters:
        pLeft - The horizontal coordinate
        pTop - The vertical coordinate
        pWidth - The width of the combo box
        pHeight - 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 coordinate
        pTop - The vertical coordinate
        pWidth - The width of the table
        pHeight - The height of the table
        pWindow - 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 column
        pContent - 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 column
        pContent - 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 table
        pContent - 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 Parameter
        pColumn - 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.