Class JKDefaultTableModel

java.lang.Object
javax.swing.table.AbstractTableModel
com.jk.core.model.table.JKDefaultTableModel
All Implemented Interfaces:
Serializable, TableModel

public class JKDefaultTableModel extends AbstractTableModel implements Serializable
This class represents a table model providing ways to manage and manipulate the rows and columns and table content.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
See Also:
  • Field Details

    • dataVector

      protected Vector dataVector
      Represents the data vector containing rows of data.
    • columnIdentifiers

      protected Vector columnIdentifiers
      Represents the vector containing the column identifiers.
  • Constructor Details

    • JKDefaultTableModel

      public JKDefaultTableModel()
      This method constructs a new JKDefaultTableModel with zero rows and columns.
    • JKDefaultTableModel

      public JKDefaultTableModel(int rowCount, int columnCount)
      This method constructs a new JKDefaultTableModel with as many rows and columns as specified by the given values.
      Parameters:
      rowCount - Specifies the number of rows in the generated table.
      columnCount - Specifies the number of columns in the generated tables.
    • JKDefaultTableModel

      public JKDefaultTableModel(Object[] columnNames, int rowCount)
      This method constructs a new JKDefaultTableModel with the specified column headers and with as many rows as specified by the given value.
      Parameters:
      columnNames - Specifies the columns headers names.
      rowCount - Specifies the number of rows in the table.
    • JKDefaultTableModel

      public JKDefaultTableModel(Object[][] data, Object[] columnNames)
      This method constructs a new JKDefaultTableModel with the specified column headers and rows filled with the provided data.
      Parameters:
      data - Specifies the data inside the rows generated.
      columnNames - Specifies the columns headers names.
    • JKDefaultTableModel

      public JKDefaultTableModel(Vector columnNames, int rowCount)
      This method constructs a new JKDefaultTableModel with the specified column headers and with as many rows as specified by the given value.
      Parameters:
      columnNames - Specifies the columns headers names.
      rowCount - Specifies the number of rows in the table.
    • JKDefaultTableModel

      public JKDefaultTableModel(Vector data, Vector columnNames)
      This method constructs a new JKDefaultTableModel with the specified column headers and rows filled with the provided data.
      Parameters:
      data - Specifies the data inside the rows generated.
      columnNames - Specifies the columns headers names.
  • Method Details

    • convertToVector

      protected static Vector convertToVector(Object[] anArray)
      This method converts the provided array to a vector.
      Parameters:
      anArray - Specifies the array to be converted.
      Returns:
      a vector representation of the given array.
    • convertToVector

      protected static Vector convertToVector(Object[][] anArray)
      This method converts the provided two-dimensional array to a vector.
      Parameters:
      anArray - Specifies the array to be converted.
      Returns:
      the vector representation of the array.
    • addColumn

      public void addColumn(Object columnName)
      This method adds a new columns to the table with the specified header name.
      Parameters:
      columnName - Specifies the new column name.
    • addColumn

      public void addColumn(Object columnName, Object[] columnData)
      This method adds a new column to the table with the specified header name and provided data.
      Parameters:
      columnName - Specifies the new column header name.
      columnData - Specifies the new column rows data.
    • addColumn

      public void addColumn(Object columnName, Vector columnData)
      This method adds a new column to the table with the specified header name and provided data.
      Parameters:
      columnName - Specifies the new column header name.
      columnData - Specifies the new column rows data.
    • addRow

      public void addRow(Object[] rowData)
      This method adds a new row to the table containing the provided data.
      Parameters:
      rowData - Specifies the new row data.
    • addRow

      public void addRow(Vector rowData)
      This method adds a new row to the table containing the provided data.
      Parameters:
      rowData - Specifies the new row data.
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.
      Specified by:
      getColumnCount in interface TableModel
      Returns:
      the number of columns in the model
    • getColumnName

      public String getColumnName(int column)
      Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
      Parameters:
      column - the index of the column
      Returns:
      the name of the column
    • getDataVector

      public Vector getDataVector()
      This method gets this table data vector.
      Returns:
      the data vector of this table model.
    • getRowCount

      public int getRowCount()
      Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.
      Specified by:
      getRowCount in interface TableModel
      Returns:
      the number of rows in the model
    • getValueAt

      public Object getValueAt(int row, int column)
      Returns the value for the cell at columnIndex and rowIndex.
      Specified by:
      getValueAt in interface TableModel
      Parameters:
      row - the row whose value is to be queried
      column - the column whose value is to be queried
      Returns:
      the value Object at the specified cell
    • insertRow

      public void insertRow(int row, Object[] rowData)
      This method insert a new row at the given index containing the provided data.
      Parameters:
      row - Specifies the new row index.
      rowData - Specifies the new row data.
    • insertRow

      public void insertRow(int row, Vector rowData)
      This method insert a new row at the given index containing the provided data.
      Parameters:
      row - Specifies the new row index.
      rowData - Specifies the new row data.
    • isCellEditable

      public boolean isCellEditable(int row, int column)
      This method checks whether this cell is editable or not.

      Always returns true.

      Specified by:
      isCellEditable in interface TableModel
      Overrides:
      isCellEditable in class AbstractTableModel
      Parameters:
      row - Specifies the row being queried.
      column - Specifies the column being queried.
      Returns:
      true.
    • moveRow

      public void moveRow(int start, int end, int to)
      This method moves a range of rows to a new location within the table.
      Parameters:
      start - Specifies the index of the first row in the range to be moved.
      end - Specifies the index of the last row in the range to be moved.
      to - Specifies the destination index where the range should be moved to.
    • newDataAvailable

      public void newDataAvailable(TableModelEvent event)
      This method notifies the table model that new data is available, triggering a table change event.
      Parameters:
      event - Specifies the TableModelEvent indicating the source of the change
    • newRowsAdded

      public void newRowsAdded(TableModelEvent e)
      This method notifies the table model that new row is added, triggering a table change event.
      Parameters:
      e - Specifies the TableModelEvent indicating the source of the change
    • removeRow

      public Object removeRow(int row)
      This method remove a row at the specified index.
      Parameters:
      row - Specifies the index of the row to be removed.
      Returns:
      the row that got removed from this table model.
    • rowsRemoved

      public void rowsRemoved(TableModelEvent event)
      This method notifies the table model that a row been removed, triggering a table change event.
      Parameters:
      event - Specifies the TableModelEvent indicating the source of the change
    • setColumnCount

      public void setColumnCount(int columnCount)
      This method sets the number of columns for this table model to the specified value.
      Parameters:
      columnCount - Specifies the new number of columns.
    • setColumnIdentifiers

      public void setColumnIdentifiers(Object[] newIdentifiers)
      This method sets the column identifiers to the provided values.
      Parameters:
      newIdentifiers - Specifies the new column identifiers.
    • setColumnIdentifiers

      public void setColumnIdentifiers(Vector columnIdentifiers)
      This method sets the column identifiers to the provided values.
      Parameters:
      columnIdentifiers - Specifies the new column identifiers.
    • setDataVector

      public void setDataVector(Object[][] dataVector, Object[] columnIdentifiers)
      This method sets the data vector of this table model to the provided data.
      Parameters:
      dataVector - Specifies the new data vector.
      columnIdentifiers - Specifies the new columns identifiers
    • setDataVector

      public void setDataVector(Vector dataVector, Vector columnIdentifiers)
      This method sets the data vector of this table model to the provided data.
      Parameters:
      dataVector - Specifies the new data vector.
      columnIdentifiers - Specifies the new columns identifiers
    • setNumRows

      public void setNumRows(int rowCount)
      This method sets the number of rows in this table model to the specified number.
      Parameters:
      rowCount - Specifies the new number of rows.
    • setRowCount

      public void setRowCount(int rowCount)
      This method sets the number of rows in this table model to the specified number.
      Parameters:
      rowCount - Specifies the new number of rows.
    • setValueAt

      public void setValueAt(Object aValue, int row, int column)
      This method changes the value at the specified coordination to the provided value.
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class AbstractTableModel
      Parameters:
      aValue - Specifies the new value.
      row - Specifies the row the value to be changed is at.
      column - Specifies the column the value to be changed is in