1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
/**
* Prepares the renderer by querying the data model for the
* value and selection state
* of the cell at <code>row</code>, <code>column</code>.
* Returns the component (may be a <code>Component</code>
* or a <code>JComponent</code>) under the event location.
* <p>
* During a printing operation, this method will configure the
* renderer without indicating selection or focus, to prevent
* them from appearing in the printed output. To do other
* customizations based on whether or not the table is being
* printed, you can check the value of
* {@link javax.swing.JComponent#isPaintingForPrint()}, either here
* or within custom renderers.
* <p>
* <b>Note:</b>
* Throughout the table package, the internal implementations always
* use this method to prepare renderers so that this default behavior
* can be safely overridden by a subclass.
*
* @param renderer the <code>TableCellRenderer</code> to prepare
* @param row the row of the cell to render, where 0 is the first row
* @param column the column of the cell to render,
* where 0 is the first column
* @return the <code>Component</code> under the event location
*/
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Object value = getValueAt(row, column);
boolean isSelected = false;
boolean hasFocus = false;
// Only indicate the selection and focused cell if not printing
if (!isPaintingForPrint()) {
isSelected = isCellSelected(row, column);
boolean rowIsLead =
(selectionModel.getLeadSelectionIndex() == row);
boolean colIsLead =
(columnModel.getSelectionModel().getLeadSelectionIndex() == column);
hasFocus = (rowIsLead && colIsLead) && isFocusOwner();
}
return renderer.getTableCellRendererComponent(this, value,
isSelected, hasFocus,
row, column);
} |
Partager