classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: fix show() and hide() in Component


From: Roman Kennke
Subject: [cp-patches] FYI: fix show() and hide() in Component
Date: Fri, 22 Jul 2005 13:15:44 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Hi,

I found that show() and hide() only should invalidate the parent of the Component (if there is one), instead of invalidating the component itself. Also, show() and hide() should trigger repaint() on that parent.

2005-07-22  Roman Kennke  <address@hidden>

        * java/awt/Component.java
        (show): Instead of invalidating the component, only invalidate
        the parent, if there is one. Also repaint this parent.
        Also, avoid NPEs by creating local references.
        (hide): Instead of invalidating the component, only invalidate
        the parent, if there is one. Also repaint this parent.
        Also, avoid NPEs by creating local references.

/Roman
Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.61
diff -u -r1.61 Component.java
--- java/awt/Component.java     6 Jul 2005 08:15:16 -0000       1.61
+++ java/awt/Component.java     22 Jul 2005 10:55:45 -0000
@@ -897,9 +897,21 @@
     if(!isVisible())
       {
         this.visible = true;
-        if (peer != null)
-          peer.setVisible(true);
-        invalidate();
+        // Avoid NullPointerExceptions by creating a local reference.
+        ComponentPeer currentPeer=peer;
+        if (currentPeer != null)
+            currentPeer.setVisible(true);
+
+        // Invalidate the parent if we have one. The component itself must
+        // not be invalidated. We also avoid NullPointerException with
+        // a local reference here.
+        Container currentParent = parent;
+        if (currentParent != null)
+          {
+            currentParent.invalidate();
+            currentParent.repaint();
+          }
+
         ComponentEvent ce =
           new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
         getToolkit().getSystemEventQueue().postEvent(ce);
@@ -930,10 +942,23 @@
   {
     if (isVisible())
       {
-        if (peer != null)
-          peer.setVisible(false);
+        // Avoid NullPointerExceptions by creating a local reference.
+        ComponentPeer currentPeer=peer;
+        if (currentPeer != null)
+            currentPeer.setVisible(false);
+        
         this.visible = false;
-        invalidate();
+        
+        // Invalidate the parent if we have one. The component itself must
+        // not be invalidated. We also avoid NullPointerException with
+        // a local reference here.
+        Container currentParent = parent;
+        if (currentParent != null)
+          {
+            currentParent.invalidate();
+            currentParent.repaint();
+          }
+
         ComponentEvent ce =
           new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
         getToolkit().getSystemEventQueue().postEvent(ce);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]