Java Code Examples for com.vaadin.flow.component.html.Div#setText()
The following examples show how to use
com.vaadin.flow.component.html.Div#setText() .
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: SynchronizedPropertyView.java From flow with Apache License 2.0 | 6 votes |
private void addSyncWithInitialValue() { add(new Text("Synchronized on 'change' event with initial value")); final Div syncOnChangeInitialValueLabel = new Div(); syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel"); Element syncOnChangeInitialValue = ElementFactory.createInput(); syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value")); syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue"); syncOnChangeInitialValue.addPropertyChangeListener("value", "change", event -> { }); syncOnChangeInitialValue.addEventListener("change", e -> { syncOnChangeInitialValueLabel .setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value")); }); syncOnChangeInitialValue.setProperty("value", "initial"); getElement().appendChild(syncOnChangeInitialValue); add(syncOnChangeInitialValueLabel); }
Example 2
Source File: ElementStyleView.java From flow with Apache License 2.0 | 6 votes |
@Override protected void onShow() { Element mainElement = getElement(); mainElement.getStyle().set("--foo", RED_BORDER); Div div = new Div(); div.setId("red-border"); div.getElement().getStyle().set("border", "var(--foo)"); div.setText("Div"); Div div2 = new Div(); div2.setId("green-border"); div2.setText("Div 2"); div2.getStyle().set("--foo", GREEN_BORDER); div2.getElement().getStyle().set("border", "var(--foo)"); add(div, div2); }
Example 3
Source File: PreserveOnRefreshView.java From flow with Apache License 2.0 | 5 votes |
public PreserveOnRefreshView() { // create unique content for this instance final String uniqueId = Long.toString(new Random().nextInt()); final Div componentId = new Div(); componentId.setId(COMPONENT_ID); componentId.setText(uniqueId); add(componentId); // add an element to keep track of number of attach events attachCounter = new Div(); attachCounter.setId(ATTACHCOUNTER_ID); attachCounter.setText("0"); add(attachCounter); // also add an element as a separate UI child. This is expected to be // transferred on refresh (mimicking dialogs and notifications) final Element looseElement = new Element("div"); looseElement.setProperty("id", NOTIFICATION_ID); looseElement.setText(uniqueId); UI.getCurrent().getElement().insertChild(0, looseElement); StreamResource resource = new StreamResource("filename", () -> new ByteArrayInputStream( "foo".getBytes(StandardCharsets.UTF_8))); Anchor download = new Anchor("", "Download file"); download.setHref(resource); download.setId("link"); add(download); }
Example 4
Source File: ImageClickView.java From flow with Apache License 2.0 | 5 votes |
public ImageClickView() { Div message = new Div(); message.setText("Before click"); message.setId("message"); Image image = new Image("", "IMAGE"); image.setId("image"); image.addClickListener(event -> message.setText("After click")); add(image, message); }
Example 5
Source File: CompositeView.java From flow with Apache License 2.0 | 5 votes |
public CompositeView() { Div name = new Div(); name.setText("Name on server: "); name.setId(CompositeNestedView.NAME_ID); NameField nameField = new NameField(); nameField.setId(CompositeNestedView.NAME_FIELD_ID); nameField.addNameChangeListener(e -> { name.setText("Name on server: " + nameField.getName()); String text = "Name value changed to " + nameField.getName() + " on the "; if (e.isFromClient()) { text += "client"; } else { text += "server"; } Div changeMessage = new Div(); changeMessage.setText(text); add(changeMessage); }); add(name, nameField, new Hr()); Input serverInput = new Input(); serverInput.setId(SERVER_INPUT_ID); NativeButton serverInputButton = createButton("Set", SERVER_INPUT_BUTTON_ID, e -> { nameField.setName(serverInput.getValue()); serverInput.clear(); }); add(new Text("Enter a value to set the name on the server"), serverInput, serverInputButton); add(new Hr()); PaperSliderComposite paperSliderComposite = new PaperSliderComposite(); paperSliderComposite.setId(COMPOSITE_PAPER_SLIDER); add(paperSliderComposite); }
Example 6
Source File: SynchronizedPropertyView.java From flow with Apache License 2.0 | 5 votes |
public InputSync(Div label, String event) { getElement().setAttribute("placeholder", "Enter text here"); label.setText("Server value on create: " + getElement().getProperty("value")); getElement().addPropertyChangeListener("value", event, e -> { }); getElement().addEventListener(event, e -> { label.setText( "Server value: " + getElement().getProperty("value")); }); }
Example 7
Source File: AttachExistingElementView.java From flow with Apache License 2.0 | 5 votes |
@Override public void onError(Node<?> parent, String tag, Element previousSibling) { Div div = new Div(); div.setText("Non-exisint element error"); div.setId("non-existing-element"); add(div); }
Example 8
Source File: LongToOpenView.java From flow with Apache License 2.0 | 5 votes |
public LongToOpenView() { Div div = new Div(); div.setText("I am the long to open view"); NativeButton back = createButton("Back", BACK_BUTTON_ID, event -> getPage().getHistory().back()); add(div, back, ScrollView.createAnchorUrl(true, ANCHOR_LINK_ID, ScrollView.ANCHOR_URL, "Anchor url to other view")); }
Example 9
Source File: SubPropertyModelTemplate.java From flow with Apache License 2.0 | 5 votes |
@EventHandler private void valueUpdated() { Div div = new Div(); div.setId("value-update"); div.setText(getStatus().getMessage()); ((HasComponents) getParent().get()).add(div); }
Example 10
Source File: SubPropertyModelTemplate.java From flow with Apache License 2.0 | 5 votes |
@EventHandler private void click(@ModelItem("status") Status statusItem) { Div div = new Div(); div.setId("statusClick"); div.setText(statusItem.getMessage()); ((HasComponents) getParent().get()).add(div); }
Example 11
Source File: CountUIsView.java From flow with Apache License 2.0 | 5 votes |
public CountUIsView() { Div count = new Div(); add(count); count.setId("uis"); // Don't show the UIs number right away on the component CTOR. Make it // explicit via action. At this point all UIs should be already // initialized NativeButton showUisNumber = new NativeButton("Show created UIs number", event -> count.setText(String.valueOf( TestingServiceInitListener.getNotNavigatedUis()))); add(showUisNumber); }
Example 12
Source File: PolymerModelPropertiesView.java From flow with Apache License 2.0 | 5 votes |
private Div addUpdateElement(String id) { Div div = new Div(); div.setText("Property value:" + getElement().getProperty("text") + ", model value: " + getModel().getText()); div.setId(id); return div; }
Example 13
Source File: PolymerPropertyChangeEventView.java From flow with Apache License 2.0 | 5 votes |
private void propertyChanged(PropertyChangeEvent event) { Div div = new Div(); div.setText("New property value: '" + event.getValue() + "', old property value: '" + event.getOldValue() + "'"); div.addClassName("change-event"); add(div); }
Example 14
Source File: PushToggleComponentVisibilityUI.java From flow with Apache License 2.0 | 5 votes |
@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 15
Source File: DnDView.java From flow with Apache License 2.0 | 5 votes |
private Div createBox(String identifier) { Div box = new Div(); box.setText(identifier); box.setWidth("100px"); box.setHeight("60px"); box.getStyle().set("border", "1px solid").set("margin", "10px"); box.setId("box-" + identifier); return box; }
Example 16
Source File: TemplateInTemplateView.java From flow with Apache License 2.0 | 5 votes |
@EventHandler private void handleClick() { getModel().setText("foo"); Div div = new Div(); div.setText("Click is handled by child template"); div.setId("click-handler"); getUI().get().add(div); }
Example 17
Source File: TemplateMappingDetectorView.java From flow with Apache License 2.0 | 5 votes |
public TemplateMappingDetectorContainer() { TemplateMappingDetector detector3 = new TemplateMappingDetector(); detector3.setId("detector2"); TemplateMappingDetectorComposite detector4 = new TemplateMappingDetectorComposite(); detector4.setId("detector3"); Div detector5 = new Div(); detector5.setId("detector4"); detector5.setText("The template itself: " + isTemplateMapped()); container.add(detector3, detector4, detector5); }
Example 18
Source File: ExportedJSFunctionView.java From flow with Apache License 2.0 | 5 votes |
@Override protected void onShow() { Div version = new Div(); version.setId("version"); add(version); String client = "window.Vaadin.Flow.clients[Object.keys(Vaadin.Flow.clients).filter(k => k !== 'TypeScript')]"; String versionJs = "var msg = '';" + "var versionInfoMethod = " + client + ".getVersionInfo;" + "if (versionInfoMethod) {" + " msg += 'version: '+versionInfoMethod().flow;" + "} else {" // + " msg += 'versionInfoMethod not published';" // + "}" // + "$0.innerHTML = msg;"; getPage().executeJs(versionJs, version); Div productionMode = new Div(); productionMode.setId("productionMode"); add(productionMode); String productionModeJs = "var productionMode = " + client + ".productionMode;" + "$0.innerText = 'Production mode: '+productionMode;"; getPage().executeJs(productionModeJs, productionMode); Div div = new Div(); div.setId("poll"); div.setText("Click to poll using JS API"); getPage().executeJs("$0.addEventListener('click', function() {" + client + ".poll();" // + "});", div); add(div); Span pollCounter = new Span("No polls"); pollCounter.setId("pollCounter"); add(pollCounter); UI.getCurrent().addPollListener(e -> { pollCount++; pollCounter.setText("Poll called " + pollCount + " times"); }); }
Example 19
Source File: View1.java From vaadin-app-layout with Apache License 2.0 | 4 votes |
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(); }
Example 20
Source File: DemoView.java From flow with Apache License 2.0 | 4 votes |
/** * Adds a demo that shows how the component looks like with specific * variants applied. * * @param componentSupplier * a method that creates the component to which variants will be * applied to * @param addVariant * a function that adds the new variant to the component * @param removeVariant * a function that removes the variant from the component * @param variantToThemeName * function that converts variant to an html theme name * @param variants * list of variants to show in the demos * @param <T> * variants' type * @param <C> * component's type */ protected <T extends Enum<?>, C extends Component & HasTheme> void addVariantsDemo( Supplier<C> componentSupplier, BiConsumer<C, T> addVariant, BiConsumer<C, T> removeVariant, Function<T, String> variantToThemeName, T... variants) { C component = componentSupplier.get(); component.setId(COMPONENT_WITH_VARIANTS_ID); Div message = new Div(); message.setText( "Toggle a variant to see how the component's appearance will change."); Div variantsToggles = new Div(); variantsToggles.setId(VARIANT_TOGGLE_BUTTONS_DIV_ID); for (T variant : variants) { if (variant.name().startsWith("LUMO_")) { String variantName = variantToThemeName.apply(variant); variantsToggles .add(new NativeButton( getButtonText(variantName, component.getThemeNames() .contains(variantName)), event -> { boolean variantPresent = component .getThemeNames() .contains(variantName); if (variantPresent) { removeVariant.accept(component, variant); } else { addVariant.accept(component, variant); } event.getSource().setText(getButtonText( variantName, !variantPresent)); })); } } addCard("Theme variants usage", message, component, variantsToggles); }