public class DataTable extends Object
JTable
.
Note for JDBC: column indexes in DataTable
are numbered
from 0, not 1.
Constructor and Description |
---|
DataTable(String[] colNames)
Convenience constructor that just takes column names, creates an
empty table that doesn't check data class.
|
DataTable(String[] colNames,
Class<?>[] colClasses,
Object[][] data)
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addRow()
Adds a new empty row to the end of the table.
|
void |
addRow(Object[] rowData)
Adds a new row to the end of the table, with specified data.
|
Class<?> |
getColumnClass(int col)
Returns the class of a column,
null if the column can
hold values of any class. |
int |
getColumnCount()
Returns the number of columns in this table.
|
String |
getColumnName(int col)
Returns the name of a column.
|
Object |
getValue(int row,
int col)
Returns the value at an existing row/column location.
|
Object |
setValue(int row,
int col,
Object val)
Sets the value at an existing row/column location.
|
int |
size()
Returns the number of rows in this table.
|
public DataTable(String[] colNames, Class<?>[] colClasses, Object[][] data)
colNames
- The names for each column. This defines the width
of the table; attempting to add rows with more or
fewer columns causes an exception. Names in this
array should be unique; if not, you will be unable
to retrieve column values by name.colClasses
- The class of each column. Attempting to add values
of the wrong class causes a ClassCastException
. May be null
or contain
null
elements to disable class checking for
the entire table or particular column respectively.data
- Initial data for the table. May be null
to create an empty table. If not null
,
this data is checked for number of columns and value
class.public DataTable(String[] colNames)
public int size()
public int getColumnCount()
public String getColumnName(int col)
public Class<?> getColumnClass(int col)
null
if the column can
hold values of any class.public Object getValue(int row, int col)
IndexOutOfBoundsException
- if the specified row or column is
not within the bounds of the table.public Object setValue(int row, int col, Object val)
ClassCastException
- if the passed value is an incorrect class
for the column.IndexOutOfBoundsException
- if the specified row or column is
not within the bounds of the table.public void addRow()
public void addRow(Object[] rowData)
IllegalArgumentException
- if the passed row is an incorrect
size for the table.ClassCastException
- if an element within the row does not have
the correct class for its column.