@Override
public void paint(Graphics2D graphics) {
super.paint(graphics);
TablePane tablePane = (TablePane)getComponent();
TablePane.RowSequence rows = tablePane.getRows();
TablePane.ColumnSequence columns = tablePane.getColumns();
int rowCount = rows.getLength();
int columnCount = columns.getLength();
int width = getWidth();
int height = getHeight();
graphics.setPaint(highlightBackgroundColor);
// Paint the highlighted rows
for (int i = 0, rowY = padding.top; i < rowCount; i++) {
TablePane.Row row = rows.get(i);
if (row.isHighlighted()) {
graphics.fillRect(0, rowY, width, rowHeights[i]);
}
rowY += rowHeights[i] + verticalSpacing;
}
// Paint the highlighted columns
for (int j = 0, columnX = padding.left; j < columnCount; j++) {
TablePane.Column column = columns.get(j);
if (column.isHighlighted()) {
graphics.fillRect(columnX, 0, columnWidths[j], height);
}
columnX += columnWidths[j] + horizontalSpacing;
}
// Paint the grid lines
if ((showHorizontalGridLines && verticalSpacing > 0)
|| (showVerticalGridLines && horizontalSpacing > 0)) {
Graphics2D gridGraphics = (Graphics2D)graphics.create();
gridGraphics.setStroke(new BasicStroke());
gridGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Find any components that span multiple rows or columns, and
// ensure that the grid lines don't get painted through their
// cells. We'll only instantiate gridClip if we find such cells
Area gridClip = null;
for (int i = 0, componentY = padding.top; i < rowCount; i++) {
for (int j = 0, componentX = padding.left; j < columnCount; j++) {
Component component = tablePane.getCellComponent(i, j);
if (component != null) {
int rowSpan = TablePane.getRowSpan(component);
int columnSpan = TablePane.getColumnSpan(component);