column

inline fun <R, V : Any> TableScope<R>.column(header: @Nls String, isEditable: Boolean = false, noinline isCellEditable: (row: R, rowIndex: Int) -> Boolean? = null, isSortable: Boolean = true, comparator: Comparator<Any?>? = null, minWidth: Int = COLUMN_MIN_WIDTH, maxWidth: Int = COLUMN_MAX_WIDTH, noinline onCellEdit: (row: R, rowIndex: Int, newValue: V?) -> Unit = { _, _, _ -> }, noinline cellContent: @Composable TableCellScope.(row: R) -> Unit? = null, noinline value: (row: R) -> V?)

Declares one column of V values, taking the column's class from the type value returns.

The class is what the table renders and edits the column's cells as, so a Boolean column draws a checkbox and hands onCellEdit a Boolean, and an Int column hands it an Int:

column("Name") { it.name }
column("Done", isEditable = true, onCellEdit = { row, _, done -> setDone(row, done) }) { it.isDone }
column("Owner", cellContent = { row -> FlowPanel { Label(row.owner) } }) { it.owner }

Where the class is not the extractor's own, declare the column with the overload that takes it.

Parameters

header

the column's header text

isEditable

whether this column's cells can be edited in place; false (the default) makes the whole column read-only

isCellEditable

decides per row whether that row's cell in this column can be edited in place, answering for every row of the column while it is declared; null (the default) leaves the answer to isEditable

isSortable

whether a click on this column's header sorts the rows by it; true (the default) lets it, while the table sorts at all

comparator

orders this column's cell values, or null (the default) to order them the way a TableRowSorter orders a column of V; applies while the table sorts at all. Hold one instance across passes: a comparator is compared by identity, so one built anew each pass - a capturing lambda, or a compareBy - sorts the rows again each pass

minWidth

the narrowest this column may be dragged or squeezed to, in pixels; 15 by default, the minimum a TableColumn sets for itself

maxWidth

the widest this column may be dragged or stretched to, in pixels; Int.MAX_VALUE - the default - leaves it unbounded

onCellEdit

invoked when a cell in this column is edited and the edit is committed, receiving the row, the row index, and the newly entered value; pair it with an isEditable of true and update the backing state from here so the next composition reflects the edit. An edit still open on a cell a later composition no longer describes - its row gone, rewritten in place, or its column rebuilt - ends there and commits nothing. An edit follows its row across rows inserted or removed elsewhere; a composition that both adds and removes rows ends an edit on any row at or past the first row where the two lists differ, and one on any row at all where the table is sorted or filtered, since a JTable cancels an editor over a change it cannot map an index across

cellContent

renders this column's cells through a composable body, against a TableCellScope and the row each cell belongs to; null (the default) renders a cell through the renderer the table picks by V

value

extracts the cell value to display for a given row

See also


fun <R> TableScope<R>.column(header: @Nls String, columnClass: Class<*>, isEditable: Boolean = false, isCellEditable: (row: R, rowIndex: Int) -> Boolean? = null, isSortable: Boolean = true, comparator: Comparator<Any?>? = null, minWidth: Int = COLUMN_MIN_WIDTH, maxWidth: Int = COLUMN_MAX_WIDTH, onCellEdit: (row: R, rowIndex: Int, newValue: Any?) -> Unit = { _, _, _ -> }, cellContent: @Composable TableCellScope.(row: R) -> Unit? = null, value: (row: R) -> Any?)

Declares one column of columnClass values.

A column's class is what the table renders and edits its cells as: a Boolean column draws a checkbox and commits a Boolean, a Number column edits through a text field and commits a number of that class. The overload without a class takes it from the type the value extractor returns and is the ordinary way to declare a column; reach for this one where the class is not the extractor's own.

Parameters

header

the column's header text

columnClass

the class of the values this column holds

isEditable

whether this column's cells can be edited in place; false (the default) makes the whole column read-only

isCellEditable

decides per row whether that row's cell in this column can be edited in place, answering for every row of the column while it is declared; null (the default) leaves the answer to isEditable

isSortable

whether a click on this column's header sorts the rows by it; true (the default) lets it, while the table sorts at all

comparator

orders this column's cell values, or null (the default) to order them the way a TableRowSorter orders a column of columnClass; applies while the table sorts at all. Hold one instance across passes: a comparator is compared by identity, so one built anew each pass - a capturing lambda, or a compareBy - sorts the rows again each pass

minWidth

the narrowest this column may be dragged or squeezed to, in pixels; 15 by default, the minimum a TableColumn sets for itself

maxWidth

the widest this column may be dragged or stretched to, in pixels; Int.MAX_VALUE - the default - leaves it unbounded

onCellEdit

invoked when a cell in this column is edited and the edit is committed, receiving the row, the row index, and the newly entered value; pair it with an isEditable of true and update the backing state from here so the next composition reflects the edit. An edit still open on a cell a later composition no longer describes - its row gone, rewritten in place, or its column rebuilt - ends there and commits nothing. An edit follows its row across rows inserted or removed elsewhere; a composition that both adds and removes rows ends an edit on any row at or past the first row where the two lists differ, and one on any row at all where the table is sorted or filtered, since a JTable cancels an editor over a change it cannot map an index across

cellContent

renders this column's cells through a composable body, against a TableCellScope and the row each cell belongs to; null (the default) renders a cell through the renderer the table picks by columnClass

value

extracts the cell value to display for a given row

See also