Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.swing.table
Class JTableHeader

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--javax.swing.table.JTableHeader

public class JTableHeader
extends JComponent
implements TableColumnModelListener, Accessible

This is the column header part of a JTable. I allow the user to change column widths and column ordering. I share the same TableColumnModel with a JTable.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.

See Also:
  `JTable`, Serialized Form

Inner Class Summary
`protected class` | `JTableHeader.AccessibleJTableHeader` The class used to obtain the accessible role for this object.

Inner classes inherited from class javax.swing.JComponent
`JComponent.AccessibleJComponent`

Field Summary
`protected TableColumnModel` | `columnModel` The TableColumnModel of the table header
`protected TableColumn` | `draggedColumn` The index of the column being dragged.
`protected int` | `draggedDistance` The distance from its original position the column has been dragged
`protected boolean` | `reorderingAllowed` Reordering of columns are allowed by the user
`protected boolean` | `resizingAllowed` Resizing of columns are allowed by the user
`protected TableColumn` | `resizingColumn` The index of the column being resized.
`protected JTable` | `table`
`protected boolean` | `updateTableInRealTime` If this flag is true, then the header will repaint the table as a column is dragged or resized.

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`

Constructor Summary
`JTableHeader()` Constructs a JTableHeader with a default TableColumnModel
`JTableHeader(TableColumnModel cm)` Constructs a JTableHeader which is initialized with cm as the column model.

Method Summary
`void` | `columnAdded(TableColumnModelEvent e)`
`int` | `columnAtPoint(java.awt.Point point)` Returns the index of the column that point lies in, or -1 if it lies outside the receiver's bounds.
`void` | `columnMarginChanged(ChangeEvent e)`
`void` | `columnMoved(TableColumnModelEvent e)`
`void` | `columnRemoved(TableColumnModelEvent e)`
`void` | `columnSelectionChanged(ListSelectionEvent e)`
`protected TableColumnModel` | `createDefaultColumnModel()` Returns the default column model object which is a DefaultTableColumnModel.
`AccessibleContext` | `getAccessibleContext()` Get the AccessibleContext associated with this JComponent
`TableColumnModel` | `getColumnModel()` Returns the TableColumnModel that contains all column inforamtion of this table header.
`TableColumn` | `getDraggedColumn()` Returns the the dragged column, if and only if a drag is in process.
`int` | `getDraggedDistance()` Returns the column's horizontal distance from its original position, if and only if a drag is in process.
`java.awt.Rectangle` | `getHeaderRect(int columnIndex)` Returns the rectangle containing the header tile at columnIndex.
`boolean` | `getReorderingAllowed()` Returns true if the receiver allows the user to rearrange columns by dragging their headers, false otherwise.
`boolean` | `getResizingAllowed()` Returns true if the receiver allows the user to resize columns by dragging between their headers, false otherwise.
`TableColumn` | `getResizingColumn()` Returns the resizing column.
`JTable` | `getTable()` Returns the header's partner table
`java.lang.String` | `getToolTipText(java.awt.event.MouseEvent event)` Overriding to allow renderer's tips to be used if it has text set.
`TableHeaderUI` | `getUI()` Returns the L&F object that renders this component.
`java.lang.String` | `getUIClassID()` Returns the name of the L&F class that renders this component.
`boolean` | `getUpdateTableInRealTime()` Returns true if the receiver updates the body of the table view in real time when a column is resized or dragged.
`protected void` | `initializeLocalVars()`
`protected java.lang.String` | `paramString()` Returns a string representation of this JTableHeader.
`void` | `resizeAndRepaint()` Properly sizes the receiver and its header view, and marks it as needing display.
`void` | `setColumnModel(TableColumnModel newModel)` Sets the column model for this table to newModel and registers with for listner notifications from the new column model.
`void` | `setDraggedColumn(TableColumn aColumn)` Sets the header's draggedColumn to aColumn
`void` | `setDraggedDistance(int distance)` Sets the header's draggedDistance to distance
`void` | `setReorderingAllowed(boolean b)` Sets whether the user can drag column headers to reorder columns.
`void` | `setResizingAllowed(boolean b)` Sets whether the user can resize columns by dragging between headers.
`void` | `setResizingColumn(TableColumn aColumn)` Sets the header's resizingColumn to aColumn
`void` | `setTable(JTable aTable)` Sets the header's partner table to aTable
`void` | `setUI(TableHeaderUI ui)` Sets the L&F object that renders this component.
`void` | `setUpdateTableInRealTime(boolean flag)` Sets whether the body of the table updates in real time when a column is resized or dragged.
`void` | `updateUI()` Notification from the UIManager that the L&F has changed.

Methods inherited from class javax.swing.JComponent
`addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update`

Methods inherited from class java.awt.Container
`add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree`

Methods inherited from class java.awt.Component
`action, add, addComponentListener, addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, getBackground, getBounds, getColorModel, getCursor, getFont, getFontMetrics, getForeground, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isEnabled, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### table

    protected JTable table

### columnModel

    protected TableColumnModel columnModel

  The TableColumnModel of the table header

### reorderingAllowed

    protected boolean reorderingAllowed

  Reordering of columns are allowed by the user

### resizingAllowed

    protected boolean resizingAllowed

  Resizing of columns are allowed by the user

### updateTableInRealTime

    protected boolean updateTableInRealTime

  If this flag is true, then the header will repaint the table as a column is dragged or resized.

### resizingColumn

    protected transient TableColumn resizingColumn

  The index of the column being resized. 0 if not resizing

### draggedColumn

    protected transient TableColumn draggedColumn

  The index of the column being dragged. 0 if not dragging

### draggedDistance

    protected transient int draggedDistance

  The distance from its original position the column has been dragged

Constructor Detail

### JTableHeader

    public JTableHeader()

  Constructs a JTableHeader with a default TableColumnModel
  See Also:
    `createDefaultColumnModel()`

### JTableHeader

    public JTableHeader(TableColumnModel cm)

  Constructs a JTableHeader which is initialized with cm as the column model. If cm is null this method will initialize the table header with a default TableColumnModel.
  Parameters:
    `cm` - The column model for the table
  See Also:
    `createDefaultColumnModel()`

Method Detail

### setTable

    public void setTable(JTable aTable)

  Sets the header's partner table to aTable

### getTable

    public JTable getTable()

  Returns the header's partner table

### setReorderingAllowed

    public void setReorderingAllowed(boolean b)

  Sets whether the user can drag column headers to reorder columns.
  Parameters:
    `flag` - true if the table view should allow reordering
  See Also:
    `getReorderingAllowed()`

### getReorderingAllowed

    public boolean getReorderingAllowed()

  Returns true if the receiver allows the user to rearrange columns by dragging their headers, false otherwise. The default is true. You can rearrange columns programmatically regardless of this setting.
  Returns:
    true if the receiver allows the user to rearrange columns by dragging their headers, false otherwise
  See Also:
    `setReorderingAllowed(boolean)`

### setResizingAllowed

    public void setResizingAllowed(boolean b)

  Sets whether the user can resize columns by dragging between headers.
  Parameters:
    `flag` - true if table view should allow resizing
  See Also:
    `getResizingAllowed()`

### getResizingAllowed

    public boolean getResizingAllowed()

  Returns true if the receiver allows the user to resize columns by dragging between their headers, false otherwise. The default is true. You can resize columns programmatically regardless of this setting.
  Returns:
    true if the receiver allows the user to resize columns by dragging between their headers, false otherwise.
  See Also:
    `setResizingAllowed(boolean)`

### getDraggedColumn

    public TableColumn getDraggedColumn()

  Returns the the dragged column, if and only if a drag is in process.
  Returns:
    the the dragged column, if and only if a drag is in process, otherwise returns null.
  See Also:
    `getDraggedDistance()`

### getDraggedDistance

    public int getDraggedDistance()

  Returns the column's horizontal distance from its original position, if and only if a drag is in process. Otherwise, the the return value is meaningless.
  Returns:
    the column's horizontal distance from its original position, if and only if a drag is in process
  See Also:
    `getDraggedColumn()`

### getResizingColumn

    public TableColumn getResizingColumn()

  Returns the resizing column. If no column is being resized this method returns null.
  Returns:
    the resizing column

### setUpdateTableInRealTime

    public void setUpdateTableInRealTime(boolean flag)

  Sets whether the body of the table updates in real time when a column is resized or dragged.
  Parameters:
    `flag` - true if tableView should update the body of the table in real time
  See Also:
    `getUpdateTableInRealTime()`

### getUpdateTableInRealTime

    public boolean getUpdateTableInRealTime()

  Returns true if the receiver updates the body of the table view in real time when a column is resized or dragged. User can set this flag to false to speed up the table's response to user resize or drag actions. The default is true.
  Returns:
    true if the table updates in real time
  See Also:
    `setUpdateTableInRealTime(boolean)`

### columnAtPoint

    public int columnAtPoint(java.awt.Point point)

  Returns the index of the column that point lies in, or -1 if it lies outside the receiver's bounds.
  Returns:
    the index of the column that point lies in, or -1 if it lies outside the receiver's bounds

### getHeaderRect

    public java.awt.Rectangle getHeaderRect(int columnIndex)

  Returns the rectangle containing the header tile at columnIndex.
  Returns:
    the rectangle containing the header tile at columnIndex
  Throws:
    java.lang.IllegalArgumentException - If columnIndex is out of range

### getToolTipText

    public java.lang.String getToolTipText(java.awt.event.MouseEvent event)

  Overriding to allow renderer's tips to be used if it has text set.
  Overrides:
    getToolTipText in class JComponent

### getUI

    public TableHeaderUI getUI()

  Returns the L&F object that renders this component.
  Returns:
    the TableHeaderUI object that renders this component

### setUI

    public void setUI(TableHeaderUI ui)

  Sets the L&F object that renders this component.
  Parameters:
    `ui` - the TableHeaderUI L&F object
  See Also:
    `UIDefaults.getUI(javax.swing.JComponent)`

### updateUI

    public void updateUI()

  Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.
  Overrides:
    updateUI in class JComponent
  See Also:
    `JComponent.updateUI()`

### getUIClassID

    public java.lang.String getUIClassID()

  Returns the name of the L&F class that renders this component.
  Returns:
    "TableHeaderUI"
  Overrides:
    getUIClassID in class JComponent
  See Also:
    `JComponent.getUIClassID()`, `UIDefaults.getUI(javax.swing.JComponent)`

### setColumnModel

    public void setColumnModel(TableColumnModel newModel)

  Sets the column model for this table to newModel and registers with for listner notifications from the new column model.
  Parameters:
    `newModel` - the new data source for this table
  Throws:
    java.lang.IllegalArgumentException - if newModel is null
  See Also:
    `getColumnModel()`

### getColumnModel

    public TableColumnModel getColumnModel()

  Returns the TableColumnModel that contains all column inforamtion of this table header.
  Returns:
    the object that provides the column state of the table
  See Also:
    `#setColumnModel()`

### columnAdded

    public void columnAdded(TableColumnModelEvent e)

  Specified by:
    columnAdded in interface TableColumnModelListener

### columnRemoved

    public void columnRemoved(TableColumnModelEvent e)

  Specified by:
    columnRemoved in interface TableColumnModelListener

### columnMoved

    public void columnMoved(TableColumnModelEvent e)

  Specified by:
    columnMoved in interface TableColumnModelListener

### columnMarginChanged

    public void columnMarginChanged(ChangeEvent e)

  Specified by:
    columnMarginChanged in interface TableColumnModelListener

### columnSelectionChanged

    public void columnSelectionChanged(ListSelectionEvent e)

  Specified by:
    columnSelectionChanged in interface TableColumnModelListener

### createDefaultColumnModel

    protected TableColumnModel createDefaultColumnModel()

  Returns the default column model object which is a DefaultTableColumnModel. Subclass can override this method to return a different column model object
  Returns:
    the default column model object

### initializeLocalVars

    protected void initializeLocalVars()

### resizeAndRepaint

    public void resizeAndRepaint()

  Properly sizes the receiver and its header view, and marks it as needing display. Also resets cursor rectangles for the header view and line scroll amounts for the JScrollPane.

### setDraggedColumn

    public void setDraggedColumn(TableColumn aColumn)

  Sets the header's draggedColumn to aColumn

### setDraggedDistance

    public void setDraggedDistance(int distance)

  Sets the header's draggedDistance to distance

### setResizingColumn

    public void setResizingColumn(TableColumn aColumn)

  Sets the header's resizingColumn to aColumn

### paramString

    protected java.lang.String paramString()

  Returns a string representation of this JTableHeader. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be `null`.

  Overriding paramString() to provide information about the specific new aspects of the JFC components.

  Returns:
    a string representation of this JTableHeader.
  Overrides:
    paramString in class JComponent

### getAccessibleContext

    public AccessibleContext getAccessibleContext()

  Get the AccessibleContext associated with this JComponent
  Specified by:
    getAccessibleContext in interface Accessible
  Returns:
    the AccessibleContext of this JComponent
  Overrides:
    getAccessibleContext in class JComponent

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Swing 1.1
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug or feature
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.