eu.beesoft.gaia.swing
Class JZebraTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by eu.beesoft.gaia.swing.JZebraTable
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable
Direct Known Subclasses:
JTreeTable

public class JZebraTable
extends javax.swing.JTable

Expands capabilities of javax.swing.JTable component.

JZebraTable has the following features:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable, javax.swing.JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.awt.Color DEFAULT
           
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, tableHeader
 
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
JZebraTable()
          Create a new instance of the JZebraTable.
 
Method Summary
 javax.swing.table.TableColumn addColumn(java.lang.String title)
          Adds a new column with given title to the column model
protected  javax.swing.table.TableColumnModel createDefaultColumnModel()
          Overriden to create and return internal column model.
protected  javax.swing.table.JTableHeader createDefaultTableHeader()
          Creates the default table header object, which is a JTableHeader.
static javax.swing.JScrollPane createScrollPane(JZebraTable table)
          Creates instance of JScrollPane for given table and other components to resolve JTable bug with AUTO_RESIZE_OFF.
 java.awt.Color getAlternateBackground()
          Returns an alternate color.
 java.awt.Color getBackgroundForRow(int row)
          Returns color used to paint background for given row.
 javax.swing.table.TableColumn getColumnByModelIndex(int modelColumnIndex)
          Maps the index of the column in the table model at modelColumnIndex to the TableColumn object.
 int getColumnCount(boolean onlyVisible)
          Returns the total number of columns in this model.
 int getColumnIndex(java.lang.Object identifier, boolean onlyVisible)
          Returns the position of the first column whose identifier equals identifier.
 java.util.List<javax.swing.table.TableColumn> getColumns(boolean onlyVisible)
          Returns a list of all the columns in the model.
 java.awt.Color getDefaultAlternateBackground()
          Returns default alternate color.
 boolean getScrollableTracksViewportHeight()
          Force the table to fill the viewport's height.
 boolean getScrollableTracksViewportWidth()
          Returns false to indicate that horizontal scrollbars are required to display the table while honoring perferred column widths.
 boolean getShowHorizontalLines()
          Returns true if the table draws horizontal lines between cells, false if it doesn't.
 boolean getShowVerticalLines()
          Returns true if the table draws vertical lines between cells, false if it doesn't.
 boolean isColumnVisible(javax.swing.table.TableColumn aColumn)
          Checks wether the specified column is currently visible.
 void pack()
          Packs table columns to their preferred sizes.
 void packColumn(int columnIndex)
          Packs the table column with given columnIndex to its preferred size.
 void paintComponent(java.awt.Graphics g)
          Add stripes between cells and behind non-opaque cells.
 java.awt.Component prepareEditor(javax.swing.table.TableCellEditor editor, int row, int col)
          Add background stripes behind edited cells.
 java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer, int row, int col)
          Add background stripes behind rendered cells.
 void setAllColumnsVisible()
          Makes all columns in this model visible
 void setAlternateBackground(java.awt.Color alternateBackground)
          Sets a new value to alternate color.
 void setColumnModel(javax.swing.table.TableColumnModel model)
          This method prevents to set other column model than that one created internally by this instance.
 void setColumnVisible(javax.swing.table.TableColumn column, boolean visible)
          Sets the visibility of the specified TableColumn.
 void setShowGrid(boolean showGrid)
          Sets whether the table draws grid lines around cells.
 void setShowHorizontalLines(boolean showHorizontalLines)
          Sets whether the table draws horizontal lines between cells.
 void setShowVerticalLines(boolean showVerticalLines)
          Sets whether the table draws vertical lines between cells.
 void setVisibleRowCount(int rows)
          Sets visible row count for the table.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, changeSelection, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, 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, 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, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, 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, checkImage, checkImage, 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

DEFAULT

public static java.awt.Color DEFAULT
Constructor Detail

JZebraTable

public JZebraTable()
Create a new instance of the JZebraTable.

Method Detail

createDefaultTableHeader

protected javax.swing.table.JTableHeader createDefaultTableHeader()
Creates the default table header object, which is a JTableHeader. A subclass can override this method to return a different table header object.

Overrides:
createDefaultTableHeader in class javax.swing.JTable
Returns:
the default table header object

getAlternateBackground

public java.awt.Color getAlternateBackground()
Returns an alternate color.

Returns:
an alternate color

setAlternateBackground

public void setAlternateBackground(java.awt.Color alternateBackground)
Sets a new value to alternate color.

Parameters:
alternateBackground - - alternate color to set

getDefaultAlternateBackground

public java.awt.Color getDefaultAlternateBackground()
Returns default alternate color.

Returns:
default alternate color

getShowHorizontalLines

public boolean getShowHorizontalLines()
Returns true if the table draws horizontal lines between cells, false if it doesn't.

Overrides:
getShowHorizontalLines in class javax.swing.JTable
Returns:
a value of the property 'showHorizontalLines'

setShowHorizontalLines

public void setShowHorizontalLines(boolean showHorizontalLines)
Sets whether the table draws horizontal lines between cells.

Overrides:
setShowHorizontalLines in class javax.swing.JTable
Parameters:
showHorizontalLines - - a new value to set

getShowVerticalLines

public boolean getShowVerticalLines()
Returns true if the table draws vertical lines between cells, false if it doesn't.

Overrides:
getShowVerticalLines in class javax.swing.JTable
Returns:
a value of the property 'showVerticalLines'

setShowVerticalLines

public void setShowVerticalLines(boolean showVerticalLines)
Sets whether the table draws vertical lines between cells.

Overrides:
setShowVerticalLines in class javax.swing.JTable
Parameters:
showVerticalLines - - a new value to set

setShowGrid

public void setShowGrid(boolean showGrid)
Sets whether the table draws grid lines around cells. Dispatches given value to methods setShowHorizontalLines(boolean) and setShowVerticalLines(boolean).

Overrides:
setShowGrid in class javax.swing.JTable
Parameters:
showGrid - - a new value to set

setVisibleRowCount

public void setVisibleRowCount(int rows)
Sets visible row count for the table.

Parameters:
rows - - a number of visible rows

paintComponent

public void paintComponent(java.awt.Graphics g)
Add stripes between cells and behind non-opaque cells.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - - the graphics context to use for painting

prepareRenderer

public java.awt.Component prepareRenderer(javax.swing.table.TableCellRenderer renderer,
                                          int row,
                                          int col)
Add background stripes behind rendered cells.

Overrides:
prepareRenderer in class javax.swing.JTable

prepareEditor

public java.awt.Component prepareEditor(javax.swing.table.TableCellEditor editor,
                                        int row,
                                        int col)
Add background stripes behind edited cells.

Overrides:
prepareEditor in class javax.swing.JTable

getBackgroundForRow

public java.awt.Color getBackgroundForRow(int row)
Returns color used to paint background for given row.

Parameters:
row - - a row number
Returns:
background color for row

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Force the table to fill the viewport's height.

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Overrides:
getScrollableTracksViewportHeight in class javax.swing.JTable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Returns false to indicate that horizontal scrollbars are required to display the table while honoring perferred column widths. Returns true if the table can be displayed in viewport without horizontal scrollbars.

Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable
Overrides:
getScrollableTracksViewportWidth in class javax.swing.JTable
Returns:
true if an auto-resizing mode is enabled and the viewport width is larger than the table's preferred size, otherwise return false.

pack

public void pack()
Packs table columns to their preferred sizes.


packColumn

public void packColumn(int columnIndex)
Packs the table column with given columnIndex to its preferred size. Asks every cell on the column for its preferred size and takes the maximum value.

Parameters:
columnIndex - - index of column to be packed

setColumnModel

public void setColumnModel(javax.swing.table.TableColumnModel model)
This method prevents to set other column model than that one created internally by this instance.

Overrides:
setColumnModel in class javax.swing.JTable
Parameters:
model - - column model to set

createDefaultColumnModel

protected final javax.swing.table.TableColumnModel createDefaultColumnModel()
Overriden to create and return internal column model.

Overrides:
createDefaultColumnModel in class javax.swing.JTable
Returns:
an internal column model

addColumn

public javax.swing.table.TableColumn addColumn(java.lang.String title)
Adds a new column with given title to the column model

Parameters:
title - - title (name or label) for column
Returns:
a newly created column

setColumnVisible

public void setColumnVisible(javax.swing.table.TableColumn column,
                             boolean visible)
Sets the visibility of the specified TableColumn. The call is ignored if the TableColumn is not found in this column model or its visibility status did not change.

Parameters:
column - - the column to show/hide
visible - - its new visibility status

setAllColumnsVisible

public void setAllColumnsVisible()
Makes all columns in this model visible


getColumnByModelIndex

public javax.swing.table.TableColumn getColumnByModelIndex(int modelColumnIndex)
Maps the index of the column in the table model at modelColumnIndex to the TableColumn object. There may me multiple TableColumn objects showing the same model column, though this is uncommon. This method will always return the first visible or else the first invisible column with the specified index.

Parameters:
modelColumnIndex - index of column in table model
Returns:
table column object or null if no such column in this column model

isColumnVisible

public boolean isColumnVisible(javax.swing.table.TableColumn aColumn)
Checks wether the specified column is currently visible.

Parameters:
aColumn - column to check
Returns:
visibility of specified column

getColumnCount

public int getColumnCount(boolean onlyVisible)
Returns the total number of columns in this model.

Parameters:
onlyVisible - - if set, only visible columns will be counted
Returns:
the number of columns in the tableColumns array

getColumns

public java.util.List<javax.swing.table.TableColumn> getColumns(boolean onlyVisible)
Returns a list of all the columns in the model.

Parameters:
onlyVisible - if set, all invisible columns will be missing from the returned list
Returns:
a list of the columns in the model

getColumnIndex

public int getColumnIndex(java.lang.Object identifier,
                          boolean onlyVisible)
Returns the position of the first column whose identifier equals identifier. Position is the the index in all visible columns if onlyVisible is true or else the index in all columns.

Parameters:
identifier - the identifier object to search for
onlyVisible - if set searches only visible columns
Returns:
the index of the first column whose identifier equals identifier
Throws:
java.lang.IllegalArgumentException - if identifier is null, or if no TableColumn has this identifier

createScrollPane

public static javax.swing.JScrollPane createScrollPane(JZebraTable table)
Creates instance of JScrollPane for given table and other components to resolve JTable bug with AUTO_RESIZE_OFF.

Parameters:
table - - the table to be wrapped by scrollpane
Returns:
created JScrollPane