javax.swing.table

Class JTableHeader

public class JTableHeader extends JComponent implements TableColumnModelListener, Accessible

Represents the table header. The header displays the column header values, is always visible event if the rest of the table scrolls up and down and supports column reordering and resizing with mouse.
Nested Class Summary
protected classJTableHeader.AccessibleJTableHeader
Field Summary
protected TableColumnModelcolumnModel
The columnModel property.
protected TableColumndraggedColumn
The draggedColumn property.
protected intdraggedDistance
The draggedDistance property.
protected booleanreorderingAllowed
The reorderingAllowed property.
protected booleanresizingAllowed
The resizingAllowed property.
protected TableColumnresizingColumn
The resizingColumn property.
protected JTabletable
The table property.
protected booleanupdateTableInRealTime
The updateTableInRealTime property.
Constructor Summary
JTableHeader()
Creates a new default instance.
JTableHeader(TableColumnModel cm)
Creates a new header.
Method Summary
voidcolumnAdded(TableColumnModelEvent event)
Receives notification when a column is added to the column model.
intcolumnAtPoint(Point point)
Returns the index of the column at the specified point.
voidcolumnMarginChanged(ChangeEvent event)
Receives notification when a column margin changes in the column model.
voidcolumnMoved(TableColumnModelEvent event)
Receives notification when a column is moved within the column model.
voidcolumnRemoved(TableColumnModelEvent event)
Receives notification when a column is removed from the column model.
voidcolumnSelectionChanged(ListSelectionEvent event)
Receives notification when the column selection has changed.
protected TableColumnModelcreateDefaultColumnModel()
Creates a default table column model.
protected TableCellRenderercreateDefaultRenderer()
Creates a default renderer.
AccessibleContextgetAccessibleContext()
Get the value of the {@link #accessibleContext} property.
TableColumnModelgetColumnModel()
Get the value of the {@link #columnModel} property.
TableCellRenderergetDefaultRenderer()
Returns the default table cell renderer.
TableColumngetDraggedColumn()
Get the column that is currently being dragged.
intgetDraggedDistance()
Get the value of the {@link #draggedDistance} property.
RectanglegetHeaderRect(int column)
Get the rectangle, occupied by the header of the given column.
booleangetReorderingAllowed()
Check if it is possible to reorder the table columns by dragging column header with mouse.
booleangetResizingAllowed()
Check if it is possible to resize the table columns by dragging the column boundary in the table header with mouse.
TableColumngetResizingColumn()
Get the column that is currently being resized.
JTablegetTable()
Get the table, having this header.
TableHeaderUIgetUI()
StringgetUIClassID()
booleangetUpdateTableInRealTime()
Get the value of the {@link #updateTableInRealTime} property.
protected voidinitializeLocalVars()
Initializes the fields and properties of this class with default values.
booleanisOpaque()
Get the value of the {@link #opaque} property.
protected StringparamString()
voidresizeAndRepaint()
Validates the layout of this table header and repaints it.
voidsetColumnModel(TableColumnModel c)
Set the value of the {@link #columnModel} property.
voidsetDefaultRenderer(TableCellRenderer cellRenderer)
Sets the default table cell renderer.
voidsetDraggedColumn(TableColumn draggingIt)
Set the column that is currently being dragged.
voidsetDraggedDistance(int d)
Set the value of the {@link #draggedDistance} property.
voidsetOpaque(boolean o)
Set the value of the {@link #opaque} property.
voidsetReorderingAllowed(boolean allowed)
Set the table ability to reorder columns by dragging column header with mouse.
voidsetResizingAllowed(boolean allowed)
Set the table ability to resize columns by dragging the column boundary in the table header with mouse.
voidsetResizingColumn(TableColumn resizingIt)
The the column that is currently being resized.
voidsetTable(JTable t)
Set the value of the {@link #table} property.
voidsetUI(TableHeaderUI u)
voidsetUpdateTableInRealTime(boolean u)
Set the value of the {@link #updateTableInRealTime} property.
voidupdateUI()

Field Detail

columnModel

protected TableColumnModel columnModel
The columnModel property.

draggedColumn

protected TableColumn draggedColumn
The draggedColumn property.

draggedDistance

protected int draggedDistance
The draggedDistance property.

reorderingAllowed

protected boolean reorderingAllowed
The reorderingAllowed property.

resizingAllowed

protected boolean resizingAllowed
The resizingAllowed property.

resizingColumn

protected TableColumn resizingColumn
The resizingColumn property.

table

protected JTable table
The table property.

updateTableInRealTime

protected boolean updateTableInRealTime
The updateTableInRealTime property.

Constructor Detail

JTableHeader

public JTableHeader()
Creates a new default instance.

JTableHeader

public JTableHeader(TableColumnModel cm)
Creates a new header. If cm is null, a new table column model is created by calling {@link #createDefaultColumnModel()}.

Parameters: cm the table column model (null permitted).

Method Detail

columnAdded

public void columnAdded(TableColumnModelEvent event)
Receives notification when a column is added to the column model.

Parameters: event the table column model event

columnAtPoint

public int columnAtPoint(Point point)
Returns the index of the column at the specified point.

Parameters: point the point.

Returns: The column index, or -1.

columnMarginChanged

public void columnMarginChanged(ChangeEvent event)
Receives notification when a column margin changes in the column model.

Parameters: event the table column model event

columnMoved

public void columnMoved(TableColumnModelEvent event)
Receives notification when a column is moved within the column model.

Parameters: event the table column model event

columnRemoved

public void columnRemoved(TableColumnModelEvent event)
Receives notification when a column is removed from the column model.

Parameters: event the table column model event

columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent event)
Receives notification when the column selection has changed.

Parameters: event the table column model event

createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
Creates a default table column model.

Returns: A default table column model.

createDefaultRenderer

protected TableCellRenderer createDefaultRenderer()
Creates a default renderer.

Returns: A default renderer.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the value of the {@link #accessibleContext} property.

Returns: The current value of the property

getColumnModel

public TableColumnModel getColumnModel()
Get the value of the {@link #columnModel} property.

Returns: The current value of the property

getDefaultRenderer

public TableCellRenderer getDefaultRenderer()
Returns the default table cell renderer.

Returns: The default table cell renderer.

getDraggedColumn

public TableColumn getDraggedColumn()
Get the column that is currently being dragged. This is used when handling the column reordering with mouse.

Returns: the column being dragged, null if none.

getDraggedDistance

public int getDraggedDistance()
Get the value of the {@link #draggedDistance} property.

Returns: The current value of the property

getHeaderRect

public Rectangle getHeaderRect(int column)
Get the rectangle, occupied by the header of the given column.

Parameters: column the column, for that the header area is requested.

Returns: the column header area.

getReorderingAllowed

public boolean getReorderingAllowed()
Check if it is possible to reorder the table columns by dragging column header with mouse. The table reordering is enabled by default, but can be disabled with {@link #setReorderingAllowed(boolean)}.

Returns: true if reordering is allowed, false otherwise.

getResizingAllowed

public boolean getResizingAllowed()
Check if it is possible to resize the table columns by dragging the column boundary in the table header with mouse. The resizing is enabled by default, but can be disabled with {@link #setResizingAllowed(boolean)}.

Returns: true if resizing is allowed, false otherwise.

getResizingColumn

public TableColumn getResizingColumn()
Get the column that is currently being resized. This is used when handling the column resizing with mouse.

Returns: the column being currently resized, null if none.

getTable

public JTable getTable()
Get the table, having this header.

Returns: the table, having this header.

getUI

public TableHeaderUI getUI()

getUIClassID

public String getUIClassID()

getUpdateTableInRealTime

public boolean getUpdateTableInRealTime()
Get the value of the {@link #updateTableInRealTime} property.

Returns: The current value of the property

initializeLocalVars

protected void initializeLocalVars()
Initializes the fields and properties of this class with default values. This is called by the constructors.

isOpaque

public boolean isOpaque()
Get the value of the {@link #opaque} property.

Returns: The current value of the property

paramString

protected String paramString()

resizeAndRepaint

public void resizeAndRepaint()
Validates the layout of this table header and repaints it. This is equivalent to revalidate() followed by repaint().

setColumnModel

public void setColumnModel(TableColumnModel c)
Set the value of the {@link #columnModel} property.

Parameters: c The new value of the property

setDefaultRenderer

public void setDefaultRenderer(TableCellRenderer cellRenderer)
Sets the default table cell renderer.

Parameters: cellRenderer the renderer.

setDraggedColumn

public void setDraggedColumn(TableColumn draggingIt)
Set the column that is currently being dragged. This is used when dragging the column with mouse. Setting to null will stop the dragging session immediately.

Parameters: draggingIt the column being currently dragged, null if none.

setDraggedDistance

public void setDraggedDistance(int d)
Set the value of the {@link #draggedDistance} property.

Parameters: d The new value of the property

setOpaque

public void setOpaque(boolean o)
Set the value of the {@link #opaque} property.

Parameters: o The new value of the property

setReorderingAllowed

public void setReorderingAllowed(boolean allowed)
Set the table ability to reorder columns by dragging column header with mouse. The table reordering is enabled by default, but can be disabled with this method.

Parameters: allowed true if reordering is allowed, false otherwise.

setResizingAllowed

public void setResizingAllowed(boolean allowed)
Set the table ability to resize columns by dragging the column boundary in the table header with mouse. The resizing is enabled by default, but can be disabled using this method.

Parameters: allowed true if resizing is allowed, false otherwise.

setResizingColumn

public void setResizingColumn(TableColumn resizingIt)
The the column that is currently being resized. This property is used when handling table resizing with mouse. Setting to null would stop the resizing session immediately.

Parameters: resizingIt the column being currently resized

setTable

public void setTable(JTable t)
Set the value of the {@link #table} property.

Parameters: t The new value of the property

setUI

public void setUI(TableHeaderUI u)

setUpdateTableInRealTime

public void setUpdateTableInRealTime(boolean u)
Set the value of the {@link #updateTableInRealTime} property.

Parameters: u The new value of the property

updateUI

public void updateUI()