Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Duda con creación de componentes al menú al invocar a método
Como les va ? siguiendo con vaadin y el ejemplo de Alejandro Duarte cuando llamo al metodo addMenuOption desde la clase MyUI no me crea el boton en el Menu cuando lo invoco ? XD
Quiero llamar a ese metodo addMenuOption desde otra clase diferente para mejorar la MVP
Solo me funciona cuando agrego el propio metodo addMenuOption y getButtonSwicth() en una misma Clase XD .
tambien coloque la variables y metodos public.
a diferencia de la Super Clase Window para ventanas que la podemos invocar con UI.getCurrent().addWindow(); desde otras clases o me equivoco ?
public class MyUI extends UI implements Receiver,View {
/*
.
. ---- MyUI ----
.
*/
MainLayout layout = new MainLayout();
layout.addMenuOption("pruebaBotonSwitch", layout.getButton());
System.out.println("getButton en UI: "+layout.getButtonSwicth);
setContent(layout);
-----------------------------------------------------------------
----- MainLayout ------
public class MainLayout extends VerticalLayout implements View {
public Button botonSwitch = new Button();
public MainLayout() {
}
public void addMenuOption(String caption, final Component component ) {
Button button = new Button(caption);
//button.setSizeFull();
button.addStyleName(ValoTheme.BUTTON_LINK);
menuLayout.addComponent(button);
button.addClickListener(e -> {
contentLayout.removeAllComponents();
contentLayout.addComponent(component);
});
}
}
public Button getButtonSwicth() {
botonSwitch.setReadOnly(true);
botonSwitch.setPrimaryStyleName("switchOff");
botonSwitch.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
boolean readOnly = botonSwitch.isReadOnly();
if(readOnly) {
botonSwitch.setReadOnly(false);
event.getButton().addStyleName("switchOn");
}else {
botonSwitch.setReadOnly(true);
event.getButton().removeStyleName("switchOn");
}
}
});
return botonSwitch;
}