Reputation: 291
I am new to Vaadin. I want to create a page where on the left side there are three options. Depending on the option selection combo boxes will appear on the right side which is specific to the option on the left. I want the combobox with label.
Name: "Combo box menu"
So far I can click the option on the left side and that displays the combo box on the right side but could not display the labels with the combo box. Label is a component and so is the combo box. When I add both to the panel. Expecting both label and combo box to showup but the last one (Combo Box) ignores the first one (Label). I am not sure why is that. I would really appreciate if someone could help me with that. Thanks
Here is my code:
HorizontalLayout hLayout;
Panel hpanel;
HorizontalSplitPanel hsplit;
VerticalSplitPanel vsplit;
tree.setImmediate(true);
tree.addItem("OP1");
tree.addItem("OP2");
tree.addItem("OP3");
hsplit.setFirstComponent(tree);
tree.addListener(new Component.Listener() {
public void componentEvent(Component.Event event) {
Object o = tree.getValue();
System.out.println("selected = " + o);
showWindowtab(o);
}
});
hpanel.setContent(hsplit);
hLayout.addComponent(hpanel);
hLayout.setSpacing(true);
final VerticalLayout main = new VerticalLayout();
main.setMargin(true);
setContent(main);
main.addComponent(hLayout);
private void showWindowtab(Object itemClicked) {
Label label = new Label("Here is example of Combo Box");
hsplit.setSecondComponent(label);
String document[] = { "X", "Y", "Z" };
ComboBox cb = new ComboBox();
cb.setInputPrompt("Select values");
cb.setInvalidAllowed(false);
cb.setNullSelectionAllowed(false);
for (int i = 0; i < document.length; i++) {
cb.addItem(document[i]);
}
cb.setImmediate(true);
setFocusedComponent(cb);
hsplit.setSecondComponent(cb);
}
Upvotes: 1
Views: 33
Reputation: 192
You call setSecondComponent() on both label and cb, so the second may override the first.
Maybe what you wanted was setfirstComponent(label)?
Another option is to call addComponent(label) on the component where you want to see your label.
Upvotes: 1