We had a problem in JTable, when the table only has one row and you
select a cell, only the single cell gets highlighted, not the entire
row, as it should (at least in rowSelectionMode). The reason is that the
other cells simply were not repainted. I tracked this to the
valueChanged() method in JTable, where we skipped the case when the
JTable has <2 rows, which simply makes no sense. I removed this.
I also fixed the calculation of the repaint rectangle to span the entire
range of the change region.
2006-05-16 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JTable.java
(valueChanged): Also repaint when table has only 1 row. Fixed
repaint rectangle to span the entire changed rows.
/Roman
Index: javax/swing/JTable.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTable.java,v
retrieving revision 1.103
diff -u -1 -0 -r1.103 JTable.java
--- javax/swing/JTable.java 15 May 2006 12:37:07 -0000 1.103
+++ javax/swing/JTable.java 16 May 2006 13:44:26 -0000
@@ -2014,28 +2014,28 @@
}
repaint();
}
/**
* Invoked when another table row is selected. It is not recommended
* to override thid method, register the listener instead.
*/
public void valueChanged (ListSelectionEvent event)
{
- // Does not make sense for the table with the single row.
- if (getRowCount() < 2)
- return;
-
- int y_gap = rowMargin;
- int y0 = (getRowHeight() + y_gap) * (event.getFirstIndex());
- int yn = (getRowHeight() + y_gap) * (event.getLastIndex()+1);
- repaint(0, y0, getWidth(), yn-y0);
+ // Repaint the changed region.
+ int first = Math.max(0, Math.min(getRowCount() - 1, event.getFirstIndex()));
+ int last = Math.max(0, Math.min(getRowCount() - 1, event.getLastIndex()));
+ Rectangle rect1 = getCellRect(first, 0, false);
+ Rectangle rect2 = getCellRect(last, getColumnCount() - 1, false);
+ SwingUtilities.computeUnion(rect2.x, rect2.y, rect2.width, rect2.height,
+ rect1);
+ repaint(rect2);
}
/**
* Returns index of the column that contains specified point
* or -1 if this table doesn't contain this point.
*
* @param point point to identify the column
* @return index of the column that contains specified point or
* -1 if this table doesn't contain this point.
*/
@@ -2364,21 +2364,20 @@
* @param renderer the renderer being prepared
* @param row the row of the cell being rendered
* @param column the column of the cell being rendered
*
* @return the component which .paint() method will paint the cell.
*/
public Component prepareRenderer(TableCellRenderer renderer,
int row,
int column)
{
-
boolean rowSelAllowed = getRowSelectionAllowed();
boolean colSelAllowed = getColumnSelectionAllowed();
boolean isSel = false;
if (rowSelAllowed && colSelAllowed || !rowSelAllowed && !colSelAllowed)
isSel = isCellSelected(row, column);
else
isSel = isRowSelected(row) && getRowSelectionAllowed()
|| isColumnSelected(column) && getColumnSelectionAllowed();
// Determine the focused cell. The focused cell is the cell at the