Package com.jk.core.model.table
Class JKDefaultTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
com.jk.core.model.table.JKDefaultTableModel
- All Implemented Interfaces:
Serializable
,TableModel
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 Summary
FieldsModifier and TypeFieldDescriptionprotected Vector
Represents the vector containing the column identifiers.protected Vector
Represents the data vector containing rows of data.Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
ConstructorsConstructorDescriptionThis method constructs a newJKDefaultTableModel
with zero rows and columns.JKDefaultTableModel
(int rowCount, int columnCount) This method constructs a newJKDefaultTableModel
with as many rows and columns as specified by the given values.JKDefaultTableModel
(Object[][] data, Object[] columnNames) This method constructs a newJKDefaultTableModel
with the specified column headers and rows filled with the provided data.JKDefaultTableModel
(Object[] columnNames, int rowCount) This method constructs a newJKDefaultTableModel
with the specified column headers and with as many rows as specified by the given value.JKDefaultTableModel
(Vector columnNames, int rowCount) This method constructs a newJKDefaultTableModel
with the specified column headers and with as many rows as specified by the given value.JKDefaultTableModel
(Vector data, Vector columnNames) This method constructs a newJKDefaultTableModel
with the specified column headers and rows filled with the provided data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method adds a new columns to the table with the specified header name.void
This method adds a new column to the table with the specified header name and provided data.void
This method adds a new column to the table with the specified header name and provided data.void
This method adds a new row to the table containing the provided data.void
This method adds a new row to the table containing the provided data.protected static Vector
convertToVector
(Object[] anArray) This method converts the provided array to a vector.protected static Vector
convertToVector
(Object[][] anArray) This method converts the provided two-dimensional array to a vector.int
Returns the number of columns in the model.getColumnName
(int column) Returns the name of the column atcolumnIndex
.This method gets this table data vector.int
Returns the number of rows in the model.getValueAt
(int row, int column) Returns the value for the cell atcolumnIndex
androwIndex
.void
This method insert a new row at the given index containing the provided data.void
This method insert a new row at the given index containing the provided data.boolean
isCellEditable
(int row, int column) This method checks whether this cell is editable or not.void
moveRow
(int start, int end, int to) This method moves a range of rows to a new location within the table.void
newDataAvailable
(TableModelEvent event) This method notifies the table model that new data is available, triggering a table change event.void
This method notifies the table model that new row is added, triggering a table change event.removeRow
(int row) This method remove a row at the specified index.void
rowsRemoved
(TableModelEvent event) This method notifies the table model that a row been removed, triggering a table change event.void
setColumnCount
(int columnCount) This method sets the number of columns for this table model to the specified value.void
setColumnIdentifiers
(Object[] newIdentifiers) This method sets the column identifiers to the provided values.void
setColumnIdentifiers
(Vector columnIdentifiers) This method sets the column identifiers to the provided values.void
setDataVector
(Object[][] dataVector, Object[] columnIdentifiers) This method sets the data vector of this table model to the provided data.void
setDataVector
(Vector dataVector, Vector columnIdentifiers) This method sets the data vector of this table model to the provided data.void
setNumRows
(int rowCount) This method sets the number of rows in this table model to the specified number.void
setRowCount
(int rowCount) This method sets the number of rows in this table model to the specified number.void
setValueAt
(Object aValue, int row, int column) This method changes the value at the specified coordination to the provided value.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
dataVector
Represents the data vector containing rows of data. -
columnIdentifiers
Represents the vector containing the column identifiers.
-
-
Constructor Details
-
JKDefaultTableModel
public JKDefaultTableModel()This method constructs a newJKDefaultTableModel
with zero rows and columns. -
JKDefaultTableModel
public JKDefaultTableModel(int rowCount, int columnCount) This method constructs a newJKDefaultTableModel
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
This method constructs a newJKDefaultTableModel
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
This method constructs a newJKDefaultTableModel
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
This method constructs a newJKDefaultTableModel
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
This method constructs a newJKDefaultTableModel
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
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
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
This method adds a new columns to the table with the specified header name.- Parameters:
columnName
- Specifies the new column name.
-
addColumn
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
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
This method adds a new row to the table containing the provided data.- Parameters:
rowData
- Specifies the new row data.
-
addRow
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. AJTable
uses this method to determine how many columns it should create and display by default.- Specified by:
getColumnCount
in interfaceTableModel
- Returns:
- the number of columns in the model
-
getColumnName
Returns the name of the column atcolumnIndex
. 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 interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
column
- the index of the column- Returns:
- the name of the column
-
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. AJTable
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 interfaceTableModel
- Returns:
- the number of rows in the model
-
getValueAt
Returns the value for the cell atcolumnIndex
androwIndex
.- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
row
- the row whose value is to be queriedcolumn
- the column whose value is to be queried- Returns:
- the value Object at the specified cell
-
insertRow
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
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 interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- 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
This method notifies the table model that new data is available, triggering a table change event.- Parameters:
event
- Specifies theTableModelEvent
indicating the source of the change
-
newRowsAdded
This method notifies the table model that new row is added, triggering a table change event.- Parameters:
e
- Specifies theTableModelEvent
indicating the source of the change
-
removeRow
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
This method notifies the table model that a row been removed, triggering a table change event.- Parameters:
event
- Specifies theTableModelEvent
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
This method sets the column identifiers to the provided values.- Parameters:
newIdentifiers
- Specifies the new column identifiers.
-
setColumnIdentifiers
This method sets the column identifiers to the provided values.- Parameters:
columnIdentifiers
- Specifies the new column identifiers.
-
setDataVector
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
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
This method changes the value at the specified coordination to the provided value.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- 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
-