getColumnSource

The getColumnSource method returns a ColumnSource that provides access to a column's data by row key, not positional index. Several overloads can cast the result to a target type so you don't need an explicit cast when the column's data type is known.

Syntax

Parameters

ParameterTypeDescription
sourceNameString

The name of the column.

clazzClass<? extends T>

The target data type to cast the ColumnSource to.

componentTypeClass<?>

The target component type, which is useful for array or vector columns. May be null.

columnDefinitionColumnDefinition<? extends T>

A ColumnDefinition whose data type and component type are used to cast the ColumnSource. The column name is taken from columnDefinition.getName().

Returns

A ColumnSource for the requested column, parameterized by the target type when clazz, componentType, or a columnDefinition is provided.

Important

ColumnSource methods like get(rowKey) use row keys, not positional indices. Row keys are the internal identifiers for rows and may not match positional indices, especially in filtered or modified tables.

Examples

A ColumnSource is most useful in code that works with row keys directly, such as a table listener. A listener's onUpdate method receives a TableUpdate that describes changed rows by row key, and a ColumnSource is how you resolve those row keys to values.

Caution

Row keys are internal identifiers, not positional indices, and cannot be assumed or made up (for example, a row key of 2 does not necessarily mean "the third row"). Always obtain row keys from a TableUpdate or the table's own RowSet via getRowSet(). For simple bulk or positional access to column data, prefer columnIterator or ColumnVectors rather than calling single-value ColumnSource accessors like getInt directly.

The following example listens for rows added to a ticking table. Each update cycle, the listener reads the new rows' values through two column sources: one retrieved with the clazz overload and one with the columnDefinition overload. Both overloads return a typed ColumnSource, so reads don't require a cast: