Java Code Examples for com.vaadin.flow.component.html.Div#setVisible()

The following examples show how to use com.vaadin.flow.component.html.Div#setVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushToggleComponentVisibilityUI.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(VaadinRequest request) {
    getPushConfiguration().setPushMode(PushMode.AUTOMATIC);
    getPushConfiguration().setTransport(Transport.WEBSOCKET_XHR);

    Div mainLayout = new Div();

    Div label = new Div();
    label.setText("Please wait");
    label.setId("label");
    label.setVisible(false);
    mainLayout.add(label);

    NativeButton button = new NativeButton("Hide me for 3 seconds");
    button.setId("hide");

    button.addClickListener(event1 -> {
        button.setVisible(false);
        label.setVisible(true);

        new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            access(() -> {
                button.setVisible(true);
                label.setVisible(false);
                push();
            });
        }).start();
    });
    mainLayout.add(button);

    add(mainLayout);
}
 
Example 2
Source File: LongPollingPushView.java    From flow with Apache License 2.0 5 votes vote down vote up
public LongPollingPushView() {
    Div parent = new Div();
    Span child = new Span("Some text");
    child.setId("child");
    parent.add(child);
    add(parent);
    parent.setVisible(false);

    add(createButton("Toggle visibility", "visibility",
            e -> parent.setVisible(!parent.isVisible())));
}
 
Example 3
Source File: VisibilityView.java    From flow with Apache License 2.0 5 votes vote down vote up
public VisibilityView() {
    setId("main");

    Div div = new Div();
    div.setText("Target to make visible/invisible");
    div.setId("visibility");
    div.setVisible(false);

    Label label = new Label("Nested element");
    label.setId("nested-label");
    div.add(label);

    NativeButton updateVisibility = createButton("Update visibility",
            "updateVisibiity",
            event -> div.setVisible(!div.isVisible()));

    NativeButton updateLabelVisibility = createButton(
            "Update label visibility", "updateLabelVisibiity",
            event -> label.setVisible(!label.isVisible()));

    NativeButton updateStyle = createButton(
            "Update target element property", "updateProperty", event -> {
                div.setClassName("foo");
                label.setClassName("bar");
            });

    add(div, updateVisibility, updateStyle, updateLabelVisibility);
}
 
Example 4
Source File: View1.java    From vaadin-app-layout with Apache License 2.0 4 votes vote down vote up
public View1() {
    VerticalLayout horizontalLayout = new VerticalLayout();
    horizontalLayout.getStyle().set("border", "1px black solid").set("padding", "10px").set("margin", "0px");
    add(horizontalLayout);

    Tab tab1 = new Tab("Tab one");
    Div page1 = new Div();
    page1.setText("Page#1");

    Tab tab2 = new Tab("Tab two");
    Div page2 = new Div();
    page2.setText("Page#2");
    page2.setVisible(false);

    Tab tab3 = new Tab("Tab three");
    Div page3 = new Div();
    page3.setText("Page#3");
    page3.setVisible(false);

    Map<Tab, Component> tabsToPages = new HashMap<>();
    tabsToPages.put(tab1, page1);
    tabsToPages.put(tab2, page2);
    tabsToPages.put(tab3, page3);
    Tabs tabs = new Tabs(tab1, tab2, tab3);
    Div pages = new Div(page1, page2, page3);

    Set<Component> pagesShown = Stream.of(page1)
            .collect(Collectors.toSet());

    tabs.addSelectedChangeListener(event -> {
        pagesShown.forEach(page -> page.setVisible(false));
        pagesShown.clear();
        Component selectedPage = tabsToPages.get(tabs.getSelectedTab());
        selectedPage.setVisible(true);
        pagesShown.add(selectedPage);
    });

    horizontalLayout.add(tabs, pages);

    horizontalLayout.add(new Button("Test", buttonClickEvent -> {
        Checkbox l = null;
        l.getLabel();
    }), new Checkbox("My Checkbox"));
    setMargin(false);
    setPadding(false);
    setSpacing(false);
    setAlignItems(Alignment.STRETCH);
    setFlexGrow(1, horizontalLayout);
    setSizeFull();
}