Copyright © 2005 Scientific Applications. All Rights Reserved.

com.sciapp.table
Class JTableRowHeader

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

public class JTableRowHeader
extends JTableHeader

JTableRowHeader represents a vertical table header, that can be used as the row header of a JTable. An instance of this class is created and employed by AdvancedJTable. JTableRowHeader uses a TableColumnModel to manage its cells. Each cell in the header has the same column width, whereas the row height is determined by the row height of the cell in the associative table.

The cells are rendered by a TableCellRenderer, which can be assigned by setDefaultRowRenderer. By default, a DefaultRowHeaderRenderer is set to render each cell in the header.

The value of each cell is determined by getColumnHeaderValue. By default, this method returns the current row number as a string.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.table.JTableHeader
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  int columnWidth
          The column width of each cell in the header.
static int DEFAULT_COLUMN_WIDTH
          The default column width of each row in the header.
protected  TableCellRenderer defaultRenderer
          The renderer that is assigned to render the cells of the header.
 
Fields inherited from class javax.swing.table.JTableHeader
columnModel, draggedColumn, draggedDistance, reorderingAllowed, resizingAllowed, resizingColumn, table, updateTableInRealTime
 
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
JTableRowHeader(TableColumnModel cm)
          Constructs a JTableRowHeader with DEFAULT_COLUMN_WIDTH as the cells' width.
JTableRowHeader(TableColumnModel cm, int columnWidth)
          Constructs a JTableRowHeader with columnWidth as the cells' width.
 
Method Summary
protected  TableCellRenderer createDefaultRowRenderer()
          Returns the default row renderer to be used.
protected  Object getColumnHeaderValue(int rowIndex)
          Returns the object to set as the header value for the cell at rowIndex.
 int getColumnWidth()
          Returns the width of each cell in the row header.
 TableCellRenderer getDefaultRowRenderer()
          Returns the default row renderer used.
 Dimension getPreferredSize()
          If the preferredSize has been set to a non-null value just returns it.
protected  void paintComponent(Graphics g)
          Calls the UI delegate's paint method, if the UI delegate is non-null.
 void setColumnWidth(int columnWidth)
          Sets the width of each cell in the row header.
 void setDefaultRowRenderer(TableCellRenderer defaultRenderer)
          Sets the default row renderer to be used.
 void setTable(JTable newTable)
          Sets the table associated with this header.
 void updateUI()
          Notification from the UIManager that the look and feel (L&F) has changed.
 
Methods inherited from class javax.swing.table.JTableHeader
columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, createDefaultColumnModel, createDefaultRenderer, getAccessibleContext, getColumnModel, getDefaultRenderer, getDraggedColumn, getDraggedDistance, getHeaderRect, getReorderingAllowed, getResizingAllowed, getResizingColumn, getTable, getToolTipText, getUI, getUIClassID, getUpdateTableInRealTime, initializeLocalVars, paramString, resizeAndRepaint, setColumnModel, setDefaultRenderer, setDraggedColumn, setDraggedDistance, setReorderingAllowed, setResizingAllowed, setResizingColumn, setUI, setUpdateTableInRealTime
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, 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, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_COLUMN_WIDTH

public static final int DEFAULT_COLUMN_WIDTH
The default column width of each row in the header.

See Also:
Constant Field Values

columnWidth

protected int columnWidth
The column width of each cell in the header.


defaultRenderer

protected TableCellRenderer defaultRenderer
The renderer that is assigned to render the cells of the header.

Constructor Detail

JTableRowHeader

public JTableRowHeader(TableColumnModel cm)
Constructs a JTableRowHeader with DEFAULT_COLUMN_WIDTH as the cells' width.


JTableRowHeader

public JTableRowHeader(TableColumnModel cm,
                       int columnWidth)
Constructs a JTableRowHeader with columnWidth as the cells' width.

Method Detail

createDefaultRowRenderer

protected TableCellRenderer createDefaultRowRenderer()
Returns the default row renderer to be used. By default, a DefaultRowHeaderRenderer is returned.

Returns:
the default table column renderer

getColumnHeaderValue

protected Object getColumnHeaderValue(int rowIndex)
Returns the object to set as the header value for the cell at rowIndex. By default, the current row number as a string is returned.

You can use the following code to return a numbering scheme based on letters instead of numbers:

String columnName = "";
for (; rowIndex >= 0; rowIndex = rowIndex / 26 - 1) {
   columnName = (char) ((char) (rowIndex % 26) + 'A') + columnName;
}
return columnName;

Returns:
the header value for the cell at rowIndex.

getColumnWidth

public int getColumnWidth()
Returns the width of each cell in the row header.

Returns:
the width of each cell.

getDefaultRowRenderer

public TableCellRenderer getDefaultRowRenderer()
Returns the default row renderer used.

Returns:
the default table column renderer for this row header.

getPreferredSize

public Dimension getPreferredSize()
If the preferredSize has been set to a non-null value just returns it. If the UI delegate's getPreferredSize method returns a non null value then return that; otherwise defer to the component's layout manager.

Overrides:
getPreferredSize in class JComponent
Returns:
the value of the preferredSize property
See Also:
JComponent.setPreferredSize(java.awt.Dimension), ComponentUI

paintComponent

protected void paintComponent(Graphics g)
Calls the UI delegate's paint method, if the UI delegate is non-null. We pass the delegate a copy of the Graphics object to protect the rest of the paint code from irrevocable changes (for example, Graphics.translate).

If you override this in a subclass you should not make permanent changes to the passed in Graphics. For example, you should not alter the clip Rectangle or modify the transform. If you need to do these operations you may find it easier to create a new Graphics from the passed in Graphics and manipulate it. Further, if you do not invoker super's implementation you must honor the opaque property, that is if this component is opaque, you must completely fill in the background in a non-opaque color. If you do not honor the opaque property you will likely see visual artifacts.

Overrides:
paintComponent in class JComponent
Parameters:
g - the Graphics object to protect
See Also:
JComponent.paint(java.awt.Graphics), ComponentUI

setColumnWidth

public void setColumnWidth(int columnWidth)
Sets the width of each cell in the row header.

Parameters:
columnWidth - the width of each cell.

setDefaultRowRenderer

public void setDefaultRowRenderer(TableCellRenderer defaultRenderer)
Sets the default row renderer to be used.

Parameters:
defaultRenderer - the default table column renderer for this row header

setTable

public void setTable(JTable newTable)
Sets the table associated with this header.

Overrides:
setTable in class JTableHeader
Parameters:
newTable - the new table

updateUI

public void updateUI()
Description copied from class: javax.swing.table.JTableHeader
Notification from the UIManager that the look and feel (L&F) has changed. Replaces the current UI object with the latest version from the UIManager.

Overrides:
updateUI in class JTableHeader
See Also:
JComponent.updateUI()

Copyright © 2005 Scientific Applications. All Rights Reserved.