How to change Vaadin 7 layout based on Combobox items selection?

542 views Asked by At

For example, if I've three items and I want to change the layout based on item selected in the combo box...how do I achieve that? Here is my sample code:

ComboBox combo = new ComboBox("My combo box");
combo.addItems("item 1", "item 2", "item 3");
combo.setTextInputAllowed(false);
combo.setNullSelectionAllowed(false);
combo.select("item 1");
combo.setImmediate(true);
combo.addValueChangeListener(new Property.ValueChangeListener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void valueChange(ValueChangeEvent event) {
Notification.show("Selected item: " + event.getProperty().getValue(), Type.HUMANIZED_MESSAGE);
}
});
ExampleGrid grid = new ExampleGrid();
grid.setWidth(100, Unit.PERCENTAGE);
Panel panel = new Panel(grid);
panel.setSizeFull();
addComponent(panel);

So there are three panels created for three items in the combo box. But, I don't know how to change the layout based on item selected inside a combo box?

Of course, I can get the first panel easily. But, I want to see all three panels based on combo box selection.

1

There are 1 answers

3
cfrick On

Keep hold of your panels there and correlate them to the items. E.g. use an Enum and store the correlation in a Map. Add a value change listener to the combobox and setVisisble(false/true) on the panels according to the selection.