This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] overriding setBackground for GtkContainerPeer


This patch adds a new method to GtkContainerPeer which overrides
GtkComponentPeer's setBackground method.  The new method will cause all
child components which do not have explicitly-set background color to
inherit the parent container's new background color.  More specifically,
the child will be repainted with the parent's background color, but the
child's background property will remain as null until setBackground is
called on the child.  This behavior matches Sun java's behavior.  Any
comments?

-David Jee


2004-01-12  David Jee  <djee@redhat.com>

        * gnu/java/awt/peer/gtk/GtkContainerPeer.java
        (setBackground): New method. Children with no explicitly-set
        background will be repainted with the parent container's new
        background color.


Index: gnu/java/awt/peer/gtk/GtkContainerPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java,v
retrieving revision 1.6
diff -u -r1.6 GtkContainerPeer.java
--- gnu/java/awt/peer/gtk/GtkContainerPeer.java	31 Dec 2003 08:58:30 -0000	1.6
+++ gnu/java/awt/peer/gtk/GtkContainerPeer.java	12 Jan 2004 20:08:19 -0000
@@ -39,6 +39,8 @@
 package gnu.java.awt.peer.gtk;
 
 import java.awt.AWTEvent;
+import java.awt.Color;
+import java.awt.Component;
 import java.awt.Container;
 import java.awt.Graphics;
 import java.awt.Insets;
@@ -136,4 +138,23 @@
   public void beginLayout () { }
   public void endLayout () { }
   public boolean isPaintPending () { return false; }
+
+  public void setBackground (Color c)
+  {
+    super.setBackground(c);
+  
+    Object components[] = ((Container) awtComponent).getComponents();
+    for (int i = 0; i < components.length; i++)
+      {
+        Component comp = (Component) components[i];
+
+        // If the child's background has not been explicitly set yet,
+        // it should inherit this container's background. This makes the
+        // child component appear as if it has a transparent background.
+        // Note that we do not alter the background property of the child,
+        // but only repaint the child with the parent's background color.
+        if (!comp.isBackgroundSet() && comp.peer != null)
+          comp.peer.setBackground(c);
+      }
+  }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]