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); }
Comment