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.

ComboBoxWithinHorizontalLayout.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.vaadin.tests.components.combobox;
  2. import java.util.Arrays;
  3. import java.util.Iterator;
  4. import com.vaadin.server.VaadinRequest;
  5. import com.vaadin.tests.components.AbstractTestUI;
  6. import com.vaadin.ui.Alignment;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.ComboBox;
  9. import com.vaadin.ui.Component;
  10. import com.vaadin.ui.HorizontalLayout;
  11. public class ComboBoxWithinHorizontalLayout extends AbstractTestUI {
  12. private ComboBox<String> comboBox;
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. comboBox = new ComboBox<>();
  16. comboBox.setWidth("100%");
  17. comboBox.setPopupWidth(null);
  18. populateWithShortItems();
  19. HorizontalLayout content = new HorizontalLayout(new Button("1"),
  20. new Button("2"), comboBox, new Button("3"));
  21. content.setWidth("100%");
  22. content.setExpandRatio(comboBox, 2.0f);
  23. Iterator<Component> i = content.iterator();
  24. while (i.hasNext()) {
  25. content.setComponentAlignment(i.next(), Alignment.BOTTOM_RIGHT);
  26. }
  27. getLayout().setSpacing(true);
  28. addComponent(content);
  29. addComponent(new Button("Toggle items", e -> {
  30. if ("Short items".equals(comboBox.getCaption())) {
  31. populateWithLongItems();
  32. } else {
  33. populateWithShortItems();
  34. }
  35. }));
  36. addComponent(new Button("Toggle spacing", e -> {
  37. content.setSpacing(!content.isSpacing());
  38. }));
  39. addComponent(new Button("Toggle expand ratio", e -> {
  40. if (content.getExpandRatio(comboBox) > 0.0f) {
  41. content.setExpandRatio(comboBox, 0.0f);
  42. } else {
  43. content.setExpandRatio(comboBox, 2.0f);
  44. }
  45. }));
  46. }
  47. private void populateWithLongItems() {
  48. comboBox.setCaption("Long items");
  49. comboBox.setItems(Arrays.asList(
  50. "First very, very, very, very, very long item to add",
  51. "Second very long item to add", "Third very long item to add"));
  52. }
  53. private void populateWithShortItems() {
  54. comboBox.setCaption("Short items");
  55. comboBox.setItems(Arrays.asList("short1", "short2", "short3"));
  56. }
  57. @Override
  58. protected Integer getTicketNumber() {
  59. return 11718;
  60. }
  61. @Override
  62. protected String getTestDescription() {
  63. return "ComboBox within HorizontalLayout should not get incorrect "
  64. + "intermediate popup positions that cause flickering.";
  65. }
  66. }