public class SortableTableModel

  1. Object
  2. AbstractTableModel
  3. SortableTableModel

ImplementsTableModel

A proxy that wraps the table model providing sorting API that can be leveraged by the table

Constructors

public SortableTableModel(int column, boolean asc, TableModel model, Comparator cmp)Sorts a table based on the given column

Methods

public TableModel getUnderlying()Returns the underlying table model
public int getSortedPosition(int row)Returns the position of the row when sorted
public int getRowCount()Returns the number of rows in the table
public int getColumnCount()Returns the number of columns in the table
public String getColumnName(int i)Returns the name of the column at the given offset
public boolean isCellEditable(int row, int column)Returns true if the cell at the given location is an editable cell
public Object getValueAt(int row, int column)Returns the value of the cell at the given location
public void setValueAt(int row, int column, Object o)Sets the value of the cell at the given location
public void addDataChangeListener(DataChangedListener d)Adds a listener to the data changed event
public void removeDataChangeListener(DataChangedListener d)Removes a listener to the data changed event
public Constraint getValidationConstraint(int row, int column)If the cell has a validation constraint it’s returned here
public Class getCellType(int row, int column)Allows the table to hint the class type of a specific cell
public String[] getMultipleChoiceOptions(int row, int column)Allows the table cell to feature multiple choice for a specific entry
public Validator getValidator()A validator can be defined here so a validation constraint can bind to a table model cell
public void setValidator(Validator validator)A validator can be defined here so a validation constraint can bind to a table model cell

Inherited methods

Constructor details

SortableTableModel

public SortableTableModel(int column, boolean asc, TableModel model, Comparator cmp)
Sorts a table based on the given column

Parameters

column int
the column to sort
asc boolean
the direction ascending/descending
model TableModel
the underlying model that will be sorted
cmp Comparator
a comparator used for comparing the cells in the column

Method details

getUnderlying

public TableModel getUnderlying()
Returns the underlying table model

Returns

the model

getSortedPosition

public int getSortedPosition(int row)
Returns the position of the row when sorted

Parameters

row int
the row in the visual table

Returns

the position in the underlying model

getRowCount

public int getRowCount()
Returns the number of rows in the table

Returns

the number of rows in the table

getColumnCount

public int getColumnCount()
Returns the number of columns in the table

Returns

the number of columns in the table

getColumnName

public String getColumnName(int i)
Returns the name of the column at the given offset

Parameters

i int
the offset for the column name

Returns

name to display at the top of the table

isCellEditable

public boolean isCellEditable(int row, int column)
Returns true if the cell at the given location is an editable cell

Parameters

row int
the cell row
column int
the cell column

Returns

true if the cell at the given location is an editable cell

getValueAt

public Object getValueAt(int row, int column)
Returns the value of the cell at the given location

Parameters

row int
the cell row
column int
the cell column

Returns

the value of the cell at the given location

setValueAt

public void setValueAt(int row, int column, Object o)
Sets the value of the cell at the given location

Parameters

row int
the cell row
column int
the cell column
o Object
the value of the cell at the given location

addDataChangeListener

public void addDataChangeListener(DataChangedListener d)
Adds a listener to the data changed event

Parameters

d DataChangedListener
the new listener

removeDataChangeListener

public void removeDataChangeListener(DataChangedListener d)
Removes a listener to the data changed event

Parameters

d DataChangedListener
the listener to remove

getValidationConstraint

public Constraint getValidationConstraint(int row, int column)
If the cell has a validation constraint it’s returned here

Parameters

row int
the row
column int
the column for the cell

Returns

null for no constraints

getCellType

public Class getCellType(int row, int column)
Allows the table to hint the class type of a specific cell

Parameters

row int
the row in the table
column int
the column

Returns

the class representing this cell

getMultipleChoiceOptions

public String[] getMultipleChoiceOptions(int row, int column)
Allows the table cell to feature multiple choice for a specific entry

Parameters

row int
the row in the table
column int
the column

Returns

the string values matching the entries or null if this isn’t a multiple choice option

getValidator

public Validator getValidator()
A validator can be defined here so a validation constraint can bind to a table model cell

Returns

the validator

setValidator

public void setValidator(Validator validator)
A validator can be defined here so a validation constraint can bind to a table model cell

Parameters

validator Validator
the validator to set