qflib 0.98.0

de.qfs.lib.gui
Class WholeRowFocusRenderer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JLabel
                          |
                          +--javax.swing.table.DefaultTableCellRenderer
                                |
                                +--de.qfs.lib.gui.WholeRowFocusRenderer
All Implemented Interfaces:
javax.accessibility.Accessible, javax.swing.border.Border, java.util.EventListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants, javax.swing.table.TableCellRenderer

public class WholeRowFocusRenderer
extends javax.swing.table.DefaultTableCellRenderer
implements javax.swing.border.Border, java.awt.event.FocusListener

This TableCellRenderer draws a focus border around a whole table row, ignoring the focused column.

The border can either be drawn in a solid color, or by tiling an icon image. The default is to use a stipple icon for the Windows Look and Feel and a solid border for the others, where the border color is the (selected) foreground color of the cells text.

Te get a smooth border, the column margin of the table's ColumnModel must be set to 0.

Since the whole focused table row needs a repaint whenever the table gains or loses the focus, the WholeRowFocusRenderer must also be added as a FocusListener to the table to take care of the necessary repaint.

Version:
$Revision: 1.7 $
Author:
Gregor Schmid
See Also:
Serialized Form

Inner classes inherited from class javax.swing.table.DefaultTableCellRenderer
javax.swing.table.DefaultTableCellRenderer.UIResource
 
Inner classes inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class javax.swing.table.DefaultTableCellRenderer
noFocusBorder
 
Fields inherited from class javax.swing.JLabel
labelFor
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WholeRowFocusRenderer()
          Create a new WholeRowFocusRenderer
 
Method Summary
 void focusGained(java.awt.event.FocusEvent e)
          Notify the renderer that the table gained the focus.
 void focusLost(java.awt.event.FocusEvent e)
          Notify the renderer that the table lost the focus.
 java.awt.Insets getBorderInsets(java.awt.Component c)
          Get the insets for the border.
 java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean selected, boolean focus, int row, int column)
          Get the Component used to paint the table cell.
 boolean isBorderOpaque()
          Query whether the border is opaque.
 void paintBorder(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)
          Draw the border.
 void setBorderColor(java.awt.Color color)
          Set the color for the focus border.
 void setBorderIcon(javax.swing.Icon icon)
          Set the icon to use for painting the border.
 void setStippleBorder()
          Set a stipple border similar to the one Windows uses.
 
Methods inherited from class javax.swing.table.DefaultTableCellRenderer
firePropertyChange, firePropertyChange, repaint, repaint, revalidate, setBackground, setForeground, setValue, updateUI, validate
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, 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
 

Constructor Detail

WholeRowFocusRenderer

public WholeRowFocusRenderer()
Create a new WholeRowFocusRenderer
Method Detail

getTableCellRendererComponent

public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table,
                                                        java.lang.Object value,
                                                        boolean selected,
                                                        boolean focus,
                                                        int row,
                                                        int column)
Get the Component used to paint the table cell.
Overrides:
getTableCellRendererComponent in class javax.swing.table.DefaultTableCellRenderer
Parameters:
table - The table to paint.
value - The value of the cell.
selected - Whether the cell is selected.
focus - Whether the cell has the focus - ignored.
row - The cell's row index.
column - The cell's column index.
Returns:
A JLabel that will paint the cell with the correct border.

setBorderColor

public void setBorderColor(java.awt.Color color)
Set the color for the focus border.
Parameters:
color - The color for the border.

setStippleBorder

public void setStippleBorder()
Set a stipple border similar to the one Windows uses.

setBorderIcon

public void setBorderIcon(javax.swing.Icon icon)
Set the icon to use for painting the border.
Parameters:
icon - The icon for the border.

getBorderInsets

public java.awt.Insets getBorderInsets(java.awt.Component c)
Get the insets for the border.
Specified by:
getBorderInsets in interface javax.swing.border.Border
Parameters:
c - Ignored.
Returns:
Insets(1, 1, 1, 1).

isBorderOpaque

public boolean isBorderOpaque()
Query whether the border is opaque.
Specified by:
isBorderOpaque in interface javax.swing.border.Border
Returns:
Always false.

paintBorder

public void paintBorder(java.awt.Component c,
                        java.awt.Graphics g,
                        int x,
                        int y,
                        int width,
                        int height)
Draw the border.
Specified by:
paintBorder in interface javax.swing.border.Border
Parameters:
c - Ignored.
g - The Graphics to draw on.
x - Left border coordinate.
y - Top border coordinate.
width - Border width.
height - Border height.

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Notify the renderer that the table gained the focus.
Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
e - Details about the event.

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Notify the renderer that the table lost the focus.
Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
e - Details about the event.

qflib 0.98.0