You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LabelWrapping.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.vaadin.tests.components.label;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.HorizontalLayout;
  5. import com.vaadin.ui.Label;
  6. public class LabelWrapping extends TestBase {
  7. @Override
  8. protected String getDescription() {
  9. return "A label inside a limited HorizontalLayout should strive to be as wide as possible and only wrap when the size of the layout is reached. The label should look the same if it is rendered initially with the layout or updated later on.";
  10. }
  11. @Override
  12. protected Integer getTicketNumber() {
  13. return 2478;
  14. }
  15. @Override
  16. protected void setup() {
  17. HorizontalLayout hl = new HorizontalLayout();
  18. hl.setWidth("250px");
  19. final String longString = "this is a somewhat long string.";
  20. final Label longLabel = new Label(longString);
  21. Button changeLength = new Button("Change length");
  22. changeLength.addClickListener(event -> {
  23. if (longLabel.getValue().equals(longString)) {
  24. longLabel.setValue("");
  25. } else {
  26. longLabel.setValue(longString);
  27. }
  28. });
  29. hl.addComponent(longLabel);
  30. hl.addComponent(changeLength);
  31. addComponent(hl);
  32. }
  33. }