javax.swing.table

Class JTableHeader

Implemented Interfaces:
Accessible, EventListener, ImageObserver, MenuContainer, Serializable, 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

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

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()
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()
Returns a debugging string representing this component.
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()

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

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 Details

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 Details

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

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

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 JComponent.accessibleContext property.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface 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

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

getUI

public TableHeaderUI getUI()

getUIClassID

public String getUIClassID()
Overrides:
getUIClassID in interface JComponent

getUpdateTableInRealTime

public boolean getUpdateTableInRealTime()
Get the value of the 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 opaque property.
Overrides:
isOpaque in interface JComponent
Returns:
The current value of the property

paramString

protected String paramString()
Returns a debugging string representing this component. The string may be empty but not null.
Overrides:
paramString in interface JComponent
Returns:
a string representing this component

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 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 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 interface JComponent
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 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 updateTableInRealTime property.
Parameters:
u - The new value of the property

updateUI

public void updateUI()
Overrides:
updateUI in interface JComponent

JTableHeader.java -- Copyright (C) 2003, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.