Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    addMember() Doesn't Display New Canvas

    I have a Layout that adds other Layouts via addMember() from the class ctor. When a button is pressed, I create another Layout and add it to the same main Layout using addMember() but it does not appear. I also tried to find out how many members were in the main Layout so I could insert it before the last member, but getMembers() returns no members. I've tried variations of draw(), redraw(), etc... on both the new Layout as well as the main Layout but with no luck. Here's a code snippet to see if someone can shed some light on what the problem might be:

    Code:
        protected Canvas createTreatmentsCanvas()
        {
            treatmentsLayout = new VLayout();
            treatmentsLayout.setWidth("100%");
            treatmentsLayout.setHeight("100%");
            treatmentsLayout.setLayoutMargin(new Integer(0));
            treatmentsLayout.setMembersMargin(0);  
            addChild(treatmentsLayout);
    
            treatmentsLayout.addMember(createTreatmentGroup());
                    
            final HLayout newGroupLayout = new HLayout();
            newGroupLayout.setWidth("100%");
            newGroupLayout.setHeight(16);
            
            treatmentsLayout.addMember(newGroupLayout);
    
            Label newGroupLabel = new Label("<nobr>Create another group</nobr>");
            newGroupLabel.setWidth(100);
            newGroupLabel.setHeight(16);
            
            newGroupLayout.addMember(newGroupLabel);
            
            ImgButton newGroupImgButton = new ImgButton();  
            newGroupImgButton.setSize(16);
            newGroupImgButton.setIconSize(16);
            newGroupImgButton.setShowRollOver(Boolean.FALSE);  
            newGroupImgButton.setShowRollOverIcon(Boolean.FALSE);  
            newGroupImgButton.setShowDown(Boolean.FALSE);  
            newGroupImgButton.setShowDownIcon(Boolean.FALSE);  
            newGroupImgButton.setSrc("generic_new.png");  
            newGroupImgButton.setActionType(SelectionType.BUTTON);
    
            newGroupLayout.addMember(newGroupImgButton);
    
            newGroupImgButton.addClickHandler(new ClickHandler()
            {
                public void onClick(ClickEvent event)
                {
                    treatmentsLayout.addMember(createTreatmentGroup(), getNextTreatmentGroupIndex());
                }
            });
            
            return (treatmentsLayout);
        }
        
        protected int getNextTreatmentGroupIndex()
        {
            int count = 0;
            
            if (treatmentsLayout.getMembers() != null)
            {
                Canvas[] members = treatmentsLayout.getMembers();
                
                for (Canvas member : members)
                {
                    if (member instanceof TreatmentGroupLayout)
                    {
                        count++;
                    }
                }
            }
            
            System.out.println("position = " + count);
            return (count);
        }

    #2
    Use the Watch Tab in the Developer Console to locate the Layout you tried to add. It may be 1px tall, offscreen, or in some other way occluded, even though successfully added as a member.

    Comment


      #3
      What's interesting is that I called createTreatmentGroup() before the layout is rendered and it displays fine, but if I call it after it's rendered, it doesn't display. I'll dig a little more. Where is the Watch tab you're referring to? I use Eclipse Galileo with the GWT 2.0 plugin. Thanks1

      Comment


        #4
        In the Developer Console - see the FAQ - you should *always* have it open.

        Comment


          #5
          The problem I was experiencing was that I was adding child layouts (e.g. HLayout) to parent layouts (e.g. VLayout). I was able to resolve the issue by adding child canvases (e.g. Canvas) to parent layouts instead, and then populating the child canvases with the actual contents.

          Comment

          Working...
          X