I’m creating a two column ListGrid. My desired effect is:
Here is what I’m experiencing:
Here is the test code:
To run the test:
- First column: auto-fitted to the width of the data. I am doing this by using field1.setAutoFitWidth(true)
- Second column: take up the remaining space of the ListGrid. I am doing this by using field2.setWidth("*")
Here is what I’m experiencing:
- If the ListGrid is drawn after the data in the ListGrid is set I get the desired effect.
- If the data in the ListGrid is set after the ListGrid is populated then the second column does not extend to full length of the ListGrid.
Here is the test code:
Code:
public class ListGridRemainingWidthTest extends VStack { private static final String FIELD1 = "One"; private static final String FIELD2 = "Two"; private static final HashMap<String, String> data = new HashMap<String, String>() { private static final long serialVersionUID = 1L; { put("cowfish", "Authoritatively extend cross-platform \"outside the box\" thinking"); put("danker", "Continually impact installed base niche markets"); put("postretirement", "Phosfluorescently synergize user-centric supply chains"); put("lockkeepers", "Holisticly strategize 24/7 collaboration and idea-sharing"); put("liquids", "Quickly mesh process-centric intellectual capital"); put("volvoxes", "Phosfluorescently leverage existing client-focused quality vectors"); put("nitride", "Conveniently innovate bricks-and-clicks schemas"); put("operator", "Credibly disintermediate efficient markets"); put("compliance", "Phosfluorescently network flexible meta-services"); put("replevin", "Enthusiastically reconceptualize cross-unit fungibility"); } }; public ListGridRemainingWidthTest() { setMembersMargin(10); addMember(new TestListGrid(true)); final TestListGrid bottomListGrid = new TestListGrid(false); addMember(getButton(bottomListGrid)); addMember(bottomListGrid); } private Button getButton(final TestListGrid bottomListGrid) { Button button = new Button("Populate Bottom ListGrid"); button.setAutoFit(true); button.setLayoutAlign(Alignment.CENTER); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { bottomListGrid.populate(); } }); return button; } private static class TestListGrid extends ListGrid { public TestListGrid(boolean populate) { setWidth(1000); setHeight(250); ListGridField field1 = new ListGridField(FIELD1); field1.setAutoFitWidth(true); ListGridField field2 = new ListGridField(FIELD2); field2.setWidth("*"); setFields(field1, field2); if (populate) { populate(); } } public void populate() { ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>(); for (Entry<String, String> entry : data.entrySet()) { ListGridRecord record = new ListGridRecord(); record.setAttribute(FIELD1, entry.getKey()); record.setAttribute(FIELD2, entry.getValue()); records.add(record); } setData(records.toArray(new ListGridRecord[0])); } } }
- new ListGridRemainingWidthTest().draw()
- The first ListGrid is populated with data and the second field is extended to the full length of the ListGrid.
- Click the button
- The second ListGrid becomes populated with data be the second field is not extended to the full length of the ListGrid.
Comment