This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 210428

Summary: Scene.validate() causes always a expensive ComponentWidget.ComponentWrapper.setBounds()
Product: platform Reporter: jmichelberger <jmichelberger>
Component: GraphAssignee: issues@platform <issues>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:
Attachments: Patch

Description jmichelberger 2012-03-30 12:40:08 UTC
Created attachment 117542 [details]
Patch

ComponentWidgets are attached as sceneListeners via its ComponentSceneListener to the Scene and a Scene.validate() call notifies the ComponentSceneListener.sceneValidated() triggering ComponentWidget.addComponent().
ComponentWidget.addComponent() sets always the new calculated Bounds to the wrapped Component, even new Bounds are equal to current set Bounds. Inside Component.setBounds() there is no check to avoid subsequent setting with same Bounds and it will always end in a expensive recalculation hell. See Component.setBounds() code.

Appended patch will avoid this call if there are no changes in new calculated Bounds.

Index: ComponentWidget.java
===================================================================
--- ComponentWidget.java	(revision 159)
+++ ComponentWidget.java	(working copy)
@@ -173,9 +173,12 @@
             component.addComponentListener (componentListener);
             componentAdded = true;
         }
-        component.removeComponentListener (componentListener);
-        componentWrapper.setBounds(scene.convertSceneToView(convertLocalToScene(getClientArea())));
-        component.addComponentListener (componentListener);
+        Rectangle newBounds = scene.convertSceneToView(convertLocalToScene(getClientArea()));
+        if (!newBounds.equals(componentWrapper.getBounds())) {
+            component.removeComponentListener (componentListener);
+            componentWrapper.setBounds(scene.convertSceneToView(convertLocalToScene(getClientArea())));
+            component.addComponentListener (componentListener);
+        }
         component.repaint();
     }