title: Why can't I modify a vaadin components state after construction of UI?
body: <p>I have a vaadin UI, that has to be dynamic (visibility of fields should change based on user selections). I tried different ways of modifying components state like setEnabled(), setLabel(), ...</p>
  
  <p>I have a ComboBox, in which the user selects values from en Enum. I added a ValueChangeListener to the ComboBox in which I try to modify Labels and other properties of some TextFields (setLabel(), setEnabled(), ...). </p>
  
  <p>My ComboBox has a ValueChangeListener like this:</p>
  
  <pre><code>myComboBox.addValueChangeListener(event -&gt; refreshLabels(event.getValue()));
  </code></pre>
  
  <p>First I wrote a method like this:</p>
  
  <pre><code>private void refreshLabels(MyEnum e){
     switch(e){
     case OPTION1: textField1.setLabel("some Text");
                   textField2.setLabel("some Text");
     case OPTION2: textField1.setLabel("some other Text");
                   textField2.setLabel("some other Text");
     }
  }
  </code></pre>
  
  <p><strong>But with this method, the Labels will not be updated.</strong></p>
  
  <p>Then I wrote another procedure for updating the Labels:</p>
  
  <pre><code>private String getNewLabel(MyEnum e){
     switch(e){
     case OPTION1: return "some Text";
     case OPTION2: return "some other Text";
     default: return "";
     }
  }
  </code></pre>
  
  <p>I also chnaged the ValueChangeListener of my ComboBox:</p>
  
  <pre><code>myComboBox.addValueChangeListener(event -&gt; textField1.setLabel(getNewLabel(event.getValue())));
  </code></pre>
  
  <p><strong>With this code, my labels are updated.</strong></p>
  
  <p>As you see, I have a workaround but with this workaround, I have to write a getNeLabel method for every Field, because all fields will need different Labels when the ComboBox is updated. I do not understand, why my first approach does not work but the second one does. In both cases, the components are already added to a Layout and displayed on the UI, when the Label is changed. Can someone maybe explain this to me?</p>