javax.swing.table
Class JTableHeader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.table.JTableHeader
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, TableColumnModelListener

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.

See Also:
Serialized Form

Nested Class Summary
protected  class JTableHeader.AccessibleJTableHeader
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  TableColumnModel columnModel
          The columnModel property.
protected  TableColumn draggedColumn
          The draggedColumn property.
protected  int draggedDistance
          The draggedDistance property.
protected  boolean reorderingAllowed
          The reorderingAllowed property.
protected  boolean resizingAllowed
          The resizingAllowed property.
protected  TableColumn resizingColumn
          The resizingColumn property.
protected  JTable table
          The table property.
protected  boolean updateTableInRealTime
          The updateTableInRealTime property.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTableHeader()
          Creates a new default instance.
JTableHeader(TableColumnModel cm)
          Creates a new header.
 
Method Summary
 void columnAdded(TableColumnModelEvent event)
          Receives notification when a column is added to the column model.
 int columnAtPoint(Point point)
          Returns the index of the column at the specified point.
 void columnMarginChanged(ChangeEvent event)
          Receives notification when a column margin changes in the column model.
 void columnMoved(TableColumnModelEvent event)
          Receives notification when a column is moved within the column model.
 void columnRemoved(TableColumnModelEvent event)
          Receives notification when a column is removed from the column model.
 void columnSelectionChanged(ListSelectionEvent event)
          Receives notification when the column selection has changed.
protected  TableColumnModel createDefaultColumnModel()
          Creates a default table column model.
protected  TableCellRenderer createDefaultRenderer()
          Creates a default renderer.
 AccessibleContext getAccessibleContext()
          Get the value of the JComponent.accessibleContext property.
 TableColumnModel getColumnModel()
          Get the value of the columnModel property.
 TableCellRenderer getDefaultRenderer()
          Returns the default table cell renderer.
 TableColumn getDraggedColumn()
          Get the column that is currently being dragged.
 int getDraggedDistance()
          Get the value of the draggedDistance property.
 Rectangle getHeaderRect(int column)
          Get the rectangle, occupied by the header of the given column.
 boolean getReorderingAllowed()
          Check if it is possible to reorder the table columns by dragging column header with mouse.
 boolean getResizingAllowed()
          Check if it is possible to resize the table columns by dragging the column boundary in the table header with mouse.
 TableColumn getResizingColumn()
          Get the column that is currently being resized.
 JTable getTable()
          Get the table, having this header.
 TableHeaderUI getUI()
           
 String getUIClassID()
          Get the value of the UIClassID property.
 boolean getUpdateTableInRealTime()
          Get the value of the updateTableInRealTime property.
protected  void initializeLocalVars()
          Initializes the fields and properties of this class with default values.
 boolean isOpaque()
          Get the value of the opaque property.
protected  String paramString()
          Return a string representation for this component, for use in debugging.
 void resizeAndRepaint()
          Validates the layout of this table header and repaints it.
 void setColumnModel(TableColumnModel c)
          Set the value of the columnModel property.
 void setDefaultRenderer(TableCellRenderer cellRenderer)
          Sets the default table cell renderer.
 void setDraggedColumn(TableColumn draggingIt)
          Set the column that is currently being dragged.
 void setDraggedDistance(int d)
          Set the value of the draggedDistance property.
 void setOpaque(boolean o)
          Set the value of the opaque property.
 void setReorderingAllowed(boolean allowed)
          Set the table ability to reorder columns by dragging column header with mouse.
 void setResizingAllowed(boolean allowed)
          Set the table ability to resize columns by dragging the column boundary in the table header with mouse.
 void setResizingColumn(TableColumn resizingIt)
          The the column that is currently being resized.
 void setTable(JTable t)
          Set the value of the table property.
 void setUI(TableHeaderUI u)
           
 void setUpdateTableInRealTime(boolean u)
          Set the value of the updateTableInRealTime property.
 void updateUI()
          This method should be overridden in subclasses.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 createDefaultColumnModel().

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

createDefaultColumnModel

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

Returns:
A default table column model.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the value of the JComponent.accessibleContext property.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
The current value of the property

getColumnModel

public TableColumnModel getColumnModel()
Get the value of the columnModel property.

Returns:
The current value of the property

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 draggedDistance property.

Returns:
The current value of the property

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 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 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.

getUpdateTableInRealTime

public boolean getUpdateTableInRealTime()
Get the value of the updateTableInRealTime property.

Returns:
The current value of the property

isOpaque

public boolean isOpaque()
Get the value of the opaque property.

Overrides:
isOpaque in class JComponent
Returns:
The current value of the property
See Also:
Component.isLightweight()

setColumnModel

public void setColumnModel(TableColumnModel c)
Set the value of the columnModel property.

Parameters:
c - The new value of the property

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 draggedDistance property.

Parameters:
d - The new value of the property

setOpaque

public void setOpaque(boolean o)
Set the value of the opaque property.

Overrides:
setOpaque in class JComponent
Parameters:
o - The new value of the property
See Also:
ComponentUI.update(java.awt.Graphics, javax.swing.JComponent)

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 table property.

Parameters:
t - The new value of the property

setUpdateTableInRealTime

public void setUpdateTableInRealTime(boolean u)
Set the value of the updateTableInRealTime property.

Parameters:
u - The new value of the property

createDefaultRenderer

protected TableCellRenderer createDefaultRenderer()
Creates a default renderer.

Returns:
A default renderer.

getDefaultRenderer

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

Returns:
The default table cell renderer.

setDefaultRenderer

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

Parameters:
cellRenderer - the renderer.

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.

paramString

protected String paramString()
Description copied from class: JComponent
Return a string representation for this component, for use in debugging.

Overrides:
paramString in class JComponent
Returns:
A string describing this component.

getUIClassID

public String getUIClassID()
Description copied from class: JComponent
Get the value of the UIClassID property. This property should be a key in the UIDefaults table managed by UIManager, the value of which is the name of a class to load for the component's JComponent.ui property.

Overrides:
getUIClassID in class JComponent
Returns:
A "symbolic" name which will map to a class to use for the component's UI, such as "ComponentUI"
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

getUI

public TableHeaderUI getUI()

setUI

public void setUI(TableHeaderUI u)

updateUI

public void updateUI()
Description copied from class: JComponent
This method should be overridden in subclasses. In JComponent, the method does nothing. In subclasses, it should a UI delegate (corresponding to the symbolic name returned from JComponent.getUIClassID()) from the UIManager, and calls JComponent.setUI(javax.swing.plaf.ComponentUI) with the new delegate.

Overrides:
updateUI in class JComponent

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.

columnAdded

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

Specified by:
columnAdded in interface TableColumnModelListener
Parameters:
event - the table column model event

columnMarginChanged

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

Specified by:
columnMarginChanged in interface TableColumnModelListener
Parameters:
event - the table column model event

columnMoved

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

Specified by:
columnMoved in interface TableColumnModelListener
Parameters:
event - the table column model event

columnRemoved

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

Specified by:
columnRemoved in interface TableColumnModelListener
Parameters:
event - the table column model event

columnSelectionChanged

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

Specified by:
columnSelectionChanged in interface TableColumnModelListener
Parameters:
event - the table column model event

resizeAndRepaint

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


initializeLocalVars

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