Package com.compomics.util
Class AlternateRowColoursJTable
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
com.compomics.util.AlternateRowColoursJTable
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,CellEditorListener
,ListSelectionListener
,RowSorterListener
,TableColumnModelListener
,TableModelListener
,Scrollable
- Direct Known Subclasses:
JTableForDB
public class AlternateRowColoursJTable extends JTable
This class provides a simple extension on a JTable, allowing even and uneven rows to
have different colours. By default, the uneven row numbers get the default background
(corresponding to getUnevenRowColor == null), while the even rows get the colour LIGHT_AQUA,
defined as a constant on this class. Both even and uneven row colours can be defined by the
caller, where setting the uneven or even rows colours to 'null' results in default behaviour
for those columns.
- Version:
- $Id: AlternateRowColoursJTable.java,v 1.1 2009/08/02 13:23:46 lennart Exp $
- Author:
- Lennart Martens
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields Modifier and Type Field Description static Color
AQUA
A rather pronounced AQUA colour (r=183, g=222, b=232).static Color
LIGHT_AQUA
A soft-tone AQUA colour (r=219, g=238, b=244).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, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Constructors Constructor Description AlternateRowColoursJTable()
Default empty constructor.AlternateRowColoursJTable(int aRows, int aCols)
Creates a new AlternateRowColoursJTable.AlternateRowColoursJTable(Object[][] rowData, Object[] columnNames)
Creates a new AlternateRowColoursJTable.AlternateRowColoursJTable(Vector rowData, Vector columnNames)
Creates a new AlternateRowColoursJTable.AlternateRowColoursJTable(TableModel dm)
Creates a new AlternateRowColoursJTable.AlternateRowColoursJTable(TableModel dm, TableColumnModel cm)
Creates a new AlternateRowColoursJTable.AlternateRowColoursJTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
Creates a new AlternateRowColoursJTable. -
Method Summary
Modifier and Type Method Description Color
getEvenRowColor()
This method returns the Color used for the even numbered rows, or 'null' if the default JTable background color is maintained for these rows.Color
getUnevenRowColor()
This method returns the Color used for the uneven numbered rows, or 'null' if the default JTable background color is maintained for these rows.Component
prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex)
Prepares the renderer by querying the data model for the value and selection state of the cell atrow
,column
.void
setEvenRowColor(Color aEvenRowColor)
Sets the colour of the even numbered rows; by default, the LIGHT_AQUA background color will be used..void
setUnevenRowColor(Color aUnevenRowColor)
Sets the colour of the uneven numbered rows; by default, the default JTable background color will be used..Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, 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, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, 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, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
AQUA
A rather pronounced AQUA colour (r=183, g=222, b=232). -
LIGHT_AQUA
A soft-tone AQUA colour (r=219, g=238, b=244). this is the default background colour for even numbered rows.
-
-
Constructor Details
-
AlternateRowColoursJTable
public AlternateRowColoursJTable()Default empty constructor. -
AlternateRowColoursJTable
public AlternateRowColoursJTable(int aRows, int aCols)Creates a new AlternateRowColoursJTable.- Parameters:
aRows
- the number of rowsaCols
- the number of columns
-
AlternateRowColoursJTable
Creates a new AlternateRowColoursJTable.- Parameters:
dm
- the table modelcm
- the table column model
-
AlternateRowColoursJTable
Creates a new AlternateRowColoursJTable.- Parameters:
dm
- the table model
-
AlternateRowColoursJTable
Creates a new AlternateRowColoursJTable.- Parameters:
dm
- the table modelcm
- the table column modelsm
- the list selection mocel
-
AlternateRowColoursJTable
Creates a new AlternateRowColoursJTable.- Parameters:
rowData
- the row data vectorcolumnNames
- the column name vector
-
AlternateRowColoursJTable
Creates a new AlternateRowColoursJTable.- Parameters:
rowData
- the row data vectorcolumnNames
- the column name vector
-
-
Method Details
-
prepareRenderer
Prepares the renderer by querying the data model for the value and selection state of the cell atrow
,column
. Returns the component (may be aComponent
or aJComponent
) under the event location.- Overrides:
prepareRenderer
in classJTable
- Parameters:
renderer
- theTableCellRenderer
to preparerowIndex
- the row of the cell to render, where 0 is the first rowvColIndex
- the column of the cell to render, where 0 is the first column- Returns:
- the
Component
under the event location
-
setEvenRowColor
Sets the colour of the even numbered rows; by default, the LIGHT_AQUA background color will be used.. The default JTable Color can be set by providing a 'null' value here.- Parameters:
aEvenRowColor
- Color to use for the even numbered rows. Is LIGHT_AQUA by default, and the JTable default Color can be set by specifying 'null' here.
-
setUnevenRowColor
Sets the colour of the uneven numbered rows; by default, the default JTable background color will be used.. This default JTable background Color can always be set by providing a 'null' value here.- Parameters:
aUnevenRowColor
- Color to use for the uneven numbered rows. Is the default JTable background by default, and this value can be set by specifying 'null' here.
-
getEvenRowColor
This method returns the Color used for the even numbered rows, or 'null' if the default JTable background color is maintained for these rows.- Returns:
- Color with the Color used for the even numbered rows, or 'null' if the default JTable background Color is used.
-
getUnevenRowColor
This method returns the Color used for the uneven numbered rows, or 'null' if the default JTable background color is maintained for these rows.- Returns:
- Color with the Color used for the uneven numbered rows, or 'null' if the default JTable background Color is used.
-