Java Tutorial/Intermediate GUIs/Table with sorting
The class HotelTablePanel (cvs) together with HotelTableModel (cvs), HotelTableColumnModel (cvs) and HotelTableRowSorter (cvs) composes a table with row sorting and special rendering.
HotelTableRowSorter
[edit | edit source]The class HotelTableRowSorter
is merely a TableRowSorter specialized
with type parameter HotelTableModel
. This is not strictly necessary but has been added for convenience, one could use TableRowSorter<HotelTableModel>
instead whereever HotelTableRowSorter
is used and this use would even reduce the number of classes in the program.
HotelTableRowSorter extends TableRowSorter<HotelTableModel>
{
...
}
HotelTableColumnModel
[edit | edit source]The class HotelTableColumnModel
extends DefaultTableColumnModel
and contains the subclasses HotelTableHeaderRenderer
and HotelTableAttributeHeaderRenderer
, which are derived from DefaultTableCellRenderer.
The column model contains the specification and configuration of table columns and the renderers support specialized rendering of table cells.
The function getTableCellRendererComponent
in DefaultTableCellRenderer
returns a component suitable for cell rendering; this component is usually the same component instance for all cells of a table and is only reconfigured to render different content for each cell, unless a column requires its own rendering.
HotelTableModel
[edit | edit source]The class HotelTableModel
is derived from AbstractTableModel
and provides access to the data structures used for the table in the way the Swing table classes expect.
HotelTablePanel
[edit | edit source]The class HotelTablePanel
extends JPanel and provides a visual container for a JTable.
(source code from vsrs.svn.sourceforge.net)