SwingListbox extends AbstractSwingContainer implements XulListbox, ListSelectionListener { public <T> void setElements( Collection<T> elements ) { this.suppressEvents = true; boundElements = elements; logger.info( "SetElements on listbox called: collection has " + elements.size() + " rows" ); this.model.removeAllElements(); this.removeItems(); for ( T t : elements ) { SwingListitem item = new SwingListitem( null, this, this.xulDomContainer, null ); String attribute = getBinding(); item.setLabel( extractLabel( t ) ); this.addChild( item ); } this.suppressEvents = false; layout(); } SwingListbox( Element self, XulComponent parent, XulDomContainer container, String tagName ); Object getManagedObject(); boolean isDisabled(); void setDisabled( boolean disabled ); void setDisabled( String disabled ); int getRows(); void setRows( int rowsToDisplay ); String getSeltype(); void setSeltype( String selType ); Orient getOrientation(); void layout(); String getOnselect(); void setOnselect( String onchange ); void valueChanged( ListSelectionEvent e ); Object getSelectedItem(); Object[] getSelectedItems(); void setSelectedItem( Object item ); void setSelectedItems( Object[] items ); void setSelectedIndices( int[] indices ); void addItem( Object item ); void removeItems(); int getRowCount(); int getSelectedIndex(); int[] getSelectedIndices(); void setSelectedindex( String idx ); void setSelectedIndex( int index ); Collection<T> getElements(); void setElements( Collection<T> elements ); String getBinding(); void setBinding( String binding ); String getCommand(); void setCommand( final String command );  }
@Test public void testSetElements() throws Exception { XulListbox box = (XulListbox) doc.getElementById( "listbox2" ); List<Person> peeps = new ArrayList<Person>(); peeps.add( new Person( "Nick" ) ); peeps.add( new Person( "Barb" ) ); peeps.add( new Person( "Kenneth" ) ); box.setElements( peeps ); assertEquals( 3, box.getRowCount() ); List<XulComponent> items = box.getChildNodes(); assertEquals( "Nick", ( (XulListitem) items.get( 0 ) ).getLabel() ); assertEquals( "Barb", ( (XulListitem) items.get( 1 ) ).getLabel() ); assertEquals( "Kenneth", ( (XulListitem) items.get( 2 ) ).getLabel() ); }