org.jdesktop.swingx.table
Class ColumnHeaderRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.jdesktop.swingx.table.ColumnHeaderRenderer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, UIResource, TableCellRenderer

public class ColumnHeaderRenderer
extends JComponent
implements TableCellRenderer, UIResource

Header renderer class which renders column sort feedback (arrows).

Additionally, it allows to customize renderer properties like Font, Alignment and similar. This part needs to go somewhere else when we switch to Mustang.

Note: #169-jdnc, #193-swingx - Header doesn't look right in winXP/mac seem - to be fixed, but could be brittle. Won't do more about it, Mustang will take care once SwingLabs is switched over to 1.6.

See Also:
Serialized Form
status.target
jdk15-glue

Nested Class Summary
 
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
static String DOWN_ICON_KEY
           
static String METAL_BORDER_HACK
           
static String UP_ICON_KEY
           
static String VISTA_BORDER_HACK
           
 
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
ColumnHeaderRenderer()
           
ColumnHeaderRenderer(JTableHeader header)
           
 
Method Summary
protected  void adjustComponentOrientation(Component stamp)
          Adjusts the Component's orientation to JXTable's CO if appropriate.
static ColumnHeaderRenderer createColumnHeaderRenderer()
           
 boolean getAntiAliasedText()
           
 Color getBackground()
          Gets the background color of this component.
 TableCellRenderer getDelegateRenderer()
           
 Icon getDownIcon()
           
 Font getFont()
          Gets the font of this component.
 Color getForeground()
          Gets the foreground color of this component.
 int getHorizontalAlignment()
           
 int getHorizontalTextPosition()
           
 Icon getIcon()
           
 int getIconTextGap()
           
static TableCellRenderer getSharedInstance()
          Returns the shared ColumnHeaderRenderer.
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex)
          Returns the component used for drawing the cell.
 Icon getUpIcon()
           
 int getVerticalAlignment()
           
 int getVerticalTextPosition()
           
 void setAntiAliasedText(boolean antiAlias)
           
 void setBackground(Color background)
          Sets the background color of this component.
 void setDownIcon(Icon icon)
           
 void setFont(Font font)
          Sets the font for this component.
 void setForeground(Color foreground)
          Sets the foreground color of this component.
 void setHorizontalAlignment(int alignment)
           
 void setHorizontalTextPosition(int textPosition)
           
 void setIcon(Icon icon)
           
 void setIconTextGap(int iconTextGap)
           
 void setUpIcon(Icon icon)
           
 void setVerticalAlignment(int alignment)
           
 void setVerticalTextPosition(int textPosition)
           
 void updateUI()
          Resets the UI property to a value from the current look and feel.
 void updateUI(JTableHeader header)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, 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, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, 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, 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, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, 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, 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, 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

UP_ICON_KEY

public static final String UP_ICON_KEY
See Also:
Constant Field Values

DOWN_ICON_KEY

public static final String DOWN_ICON_KEY
See Also:
Constant Field Values

VISTA_BORDER_HACK

public static final String VISTA_BORDER_HACK
See Also:
Constant Field Values

METAL_BORDER_HACK

public static final String METAL_BORDER_HACK
See Also:
Constant Field Values
Constructor Detail

ColumnHeaderRenderer

public ColumnHeaderRenderer()

ColumnHeaderRenderer

public ColumnHeaderRenderer(JTableHeader header)
Method Detail

getSharedInstance

public static TableCellRenderer getSharedInstance()
Returns the shared ColumnHeaderRenderer.

Returns:
the shared header renderer.

createColumnHeaderRenderer

public static ColumnHeaderRenderer createColumnHeaderRenderer()
Returns:
a ColumnHeaderRenderer

getTableCellRendererComponent

public Component getTableCellRendererComponent(JTable table,
                                               Object value,
                                               boolean isSelected,
                                               boolean hasFocus,
                                               int rowIndex,
                                               int columnIndex)
Description copied from interface: javax.swing.table.TableCellRenderer
Returns the component used for drawing the cell. This method is used to configure the renderer appropriately before drawing.

Specified by:
getTableCellRendererComponent in interface TableCellRenderer
Parameters:
table - the JTable that is asking the renderer to draw; can be null
value - the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
hasFocus - if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
rowIndex - the row index of the cell being drawn. When drawing the header, the value of row is -1
columnIndex - the column index of the cell being drawn

adjustComponentOrientation

protected void adjustComponentOrientation(Component stamp)
Adjusts the Component's orientation to JXTable's CO if appropriate. Here: always.

Parameters:
stamp - the component to adjust.

setAntiAliasedText

public void setAntiAliasedText(boolean antiAlias)

getAntiAliasedText

public boolean getAntiAliasedText()

setBackground

public void setBackground(Color background)
Description copied from class: javax.swing.JComponent
Sets the background color of this component.

Overrides:
setBackground in class JComponent
Parameters:
background - the desired background Color
See Also:
Component.getBackground()

getBackground

public Color getBackground()
Description copied from class: java.awt.Component
Gets the background color of this component.

Overrides:
getBackground in class Component
Returns:
this component's background color; if this component does not have a background color, the background color of its parent is returned
See Also:
Component.setBackground(java.awt.Color)

setForeground

public void setForeground(Color foreground)
Description copied from class: javax.swing.JComponent
Sets the foreground color of this component.

Overrides:
setForeground in class JComponent
Parameters:
foreground - the desired foreground Color
See Also:
Component.getForeground()

getForeground

public Color getForeground()
Description copied from class: java.awt.Component
Gets the foreground color of this component.

Overrides:
getForeground in class Component
Returns:
this component's foreground color; if this component does not have a foreground color, the foreground color of its parent is returned
See Also:
Component.setForeground(java.awt.Color)

setFont

public void setFont(Font font)
Description copied from class: javax.swing.JComponent
Sets the font for this component.

Overrides:
setFont in class JComponent
Parameters:
font - the desired Font for this component
See Also:
Component.getFont()

getFont

public Font getFont()
Description copied from class: java.awt.Component
Gets the font of this component.

Specified by:
getFont in interface MenuContainer
Overrides:
getFont in class Component
Returns:
this component's font; if a font has not been set for this component, the font of its parent is returned
See Also:
Component.setFont(java.awt.Font)

setDownIcon

public void setDownIcon(Icon icon)

getDownIcon

public Icon getDownIcon()

setUpIcon

public void setUpIcon(Icon icon)

getUpIcon

public Icon getUpIcon()

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)

getHorizontalAlignment

public int getHorizontalAlignment()

setHorizontalTextPosition

public void setHorizontalTextPosition(int textPosition)

getHorizontalTextPosition

public int getHorizontalTextPosition()

setIcon

public void setIcon(Icon icon)

getIcon

public Icon getIcon()

setIconTextGap

public void setIconTextGap(int iconTextGap)

getIconTextGap

public int getIconTextGap()

setVerticalAlignment

public void setVerticalAlignment(int alignment)

getVerticalAlignment

public int getVerticalAlignment()

setVerticalTextPosition

public void setVerticalTextPosition(int textPosition)

getVerticalTextPosition

public int getVerticalTextPosition()

getDelegateRenderer

public TableCellRenderer getDelegateRenderer()
Returns:
the delegate renderer.

updateUI

public void updateUI()
Description copied from class: javax.swing.JComponent
Resets the UI property to a value from the current look and feel. JComponent subclasses must override this method like this:
   public void updateUI() {
      setUI((SliderUI)UIManager.getUI(this);
   }
  

Overrides:
updateUI in class JComponent
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), UIManager.getLookAndFeel(), UIManager.getUI(javax.swing.JComponent)

updateUI

public void updateUI(JTableHeader header)