Hi there,

Am 3.11.2005 schrieb "Lillian Angel" <[EMAIL PROTECTED]>:

>For DefaultTableCellRenderer, Roman suggested I fix it this way. Both
>ways work, but this looks a bit more intuitive.
>
>2005-11-03  Lillian Angel  <[EMAIL PROTECTED]>
>
[..]
>        * javax/swing/table/DefaultTableCellRenderer.java
>        (getTableCellRendererComponent): Fixed indentation, and changed
>        to set the background color if it is not an instance of
>       ColorUIResource. Prevents overriding a user-set color.

Sorry, my suggestion was wrong. Shame on me. A testcase I've written
shows that the following patch is right (and thinking about ot, it is
even more intuitive than the last one).

2005-11-03  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/table/DefaultTableCellRenderer.java
        (background): New field.
        (foreground): New field.
        (setBackground): Store the color that is set here.
        (setForeground): Store the color that is set here.
        (getTableCellRendererComponent): For the unselected color, set the
        value of the foreground or background fields if not null,
otherwise
        the value of the according table properties. Don't change
        the color in the focused clause.

/Roman
Index: javax/swing/table/DefaultTableCellRenderer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/table/DefaultTableCellRenderer.java,v
retrieving revision 1.19
diff -u -r1.19 DefaultTableCellRenderer.java
--- javax/swing/table/DefaultTableCellRenderer.java	3 Nov 2005 22:06:11 -0000	1.19
+++ javax/swing/table/DefaultTableCellRenderer.java	3 Nov 2005 22:24:31 -0000
@@ -72,6 +72,16 @@
   }
 
   /**
+   * Stores the color set by setForeground().
+   */
+  Color foreground;
+
+  /**
+   * Stores the color set by setBackground().
+   */
+  Color background;
+
+  /**
    * Creates a default table cell renderer with an empty border.
    */
   public DefaultTableCellRenderer()
@@ -87,6 +97,7 @@
   public void setForeground(Color c)
   {
     super.setForeground(c);
+    foreground = c;
   }
 
   /**
@@ -97,6 +108,7 @@
   public void setBackground(Color c)
   {
     super.setBackground(c);
+    background = c;
   }
 
   /**
@@ -146,16 +158,18 @@
       }
     else
       {
-        setBackground(table.getBackground());
-        setForeground(table.getForeground());
+        if (background != null)
+          setBackground(background);
+        else
+          setBackground(table.getBackground());
+        if (foreground != null)
+          setForeground(foreground);
+        else
+          setForeground(table.getForeground());
       }
 
     if (hasFocus)
-      {
-        if (!(getBackground() instanceof ColorUIResource)) 
-          setBackground(table.getBackground());
-        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
-      }
+      setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
     else
       setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
 
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to