Hi, Here comes another fix for the table cell renderer. I hope that this is the correct thing to do. So much fun with underspecified APIs :-/. Thanks go to lillian who has been incredibly patient to discuss this with me on IRC, as well as testing.
2005-11-04 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/table/DefaultTableCellRenderer.java (updateUI): Set the background and foreground color fields to null here so that installing the LabelUI does not interfere with our custom set colors. (getTableCellRendererComponent): Only set UI focus colors when cell is actually editable. Added optimization for the case when background is equal to table background. /Roman
Index: javax/swing/table/DefaultTableCellRenderer.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/table/DefaultTableCellRenderer.java,v retrieving revision 1.20 retrieving revision 1.22 diff -u -r1.20 -r1.22 --- javax/swing/table/DefaultTableCellRenderer.java 3 Nov 2005 22:26:10 -0000 1.20 +++ javax/swing/table/DefaultTableCellRenderer.java 4 Nov 2005 15:10:20 -0000 1.22 @@ -50,7 +50,6 @@ import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.JTextField; -import javax.swing.plaf.ColorUIResource; /** * Class to display every cells. @@ -120,6 +119,8 @@ public void updateUI() { super.updateUI(); + background = null; + foreground = null; } /** @@ -153,29 +154,41 @@ if (isSelected) { - setBackground(table.getSelectionBackground()); - setForeground(table.getSelectionForeground()); + super.setBackground(table.getSelectionBackground()); + super.setForeground(table.getSelectionForeground()); } else { if (background != null) - setBackground(background); + super.setBackground(background); else - setBackground(table.getBackground()); + super.setBackground(table.getBackground()); if (foreground != null) - setForeground(foreground); + super.setForeground(foreground); else - setForeground(table.getForeground()); + super.setForeground(table.getForeground()); } if (hasFocus) - setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); + { + setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); + if (table.isCellEditable(row, column)) + { + super.setBackground(UIManager.getColor("Table.focusCellBackground")); + super.setForeground(UIManager.getColor("Table.focusCellForeground")); + } + } else setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setEnabled(table.isEnabled()); setFont(table.getFont()); + // If the current background is equal to the table's background, then we + // can avoid filling the background by setting the renderer opaque. + Color back = getBackground(); + setOpaque(back != null && back.equals(table.getBackground())); + return this; }
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches