title: Custom attributes fxml
body: <p>I was trying to simplify my markup for an options application I'm writing and decided to subclass some JavaFX components with custom attributes.
  The way to do this, apparently, is to provide getters and setters for the attributes like in my interface:</p>
  
  <pre><code>public interface ConfigNode {
      public String getSection();
      public void setSection(String section);
  
      public String getKey();
      public void setKey(String key);
  
      public Wini getConfig();
      public void setConfig(Wini config);
  }
  </code></pre>
  
  <p>The corresponding fxml code:</p>
  
  <pre><code>&lt;GridPane fx:id="root" xmlns:fx="http://javafx.com/fxml" fx:controller="org.syntax_austria.league_config.OptionController" disable="true"&gt;
      &lt;ResolutionBox /&gt;
      &lt;QualityBox section="Performance" key="ShadowsEnabled" /&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>This doesn't work, though, telling me that both attributes are read-only.</p>
  
  <p>I found some example where the setters took Objects as parameters and tried that, to no avail. Help would be appreciated.</p>
  
  <p>EDIT: since asked, here is one implementer:</p>
  
  <pre><code>public class ModeBox&lt;T&gt; extends ChoiceBox&lt;T&gt; implements ConfigNode {
      String section;
      String key;
      Wini config;
  
      @Override
      public String getSection() {
          return section;
      }
  
      @Override
      public void setSection(String section) {
          if(section instanceof String)
              this.section = (String)section;
      }
  
      @Override
      public String getKey() {
          return key;
      }
  
      @Override
      public void setKey(String key) {
          if(key instanceof String)
              this.key = (String)key;
      }
  
      @Override
      public Wini getConfig() {
          return config;
      }
  
      @Override
      public void setConfig(Wini config) {
          this.config = config;
          getSelectionModel().select(config.get(section, key, Integer.class));
          getSelectionModel().selectedIndexProperty().addListener(new ChangeListener&lt;Number&gt;() {
              @Override
              public void changed(ObservableValue&lt;? extends Number&gt; observableValue, Number number, Number number2) {
                  getConfig().put(section, key, number2.intValue());
              }
          });
      }
  }
  </code></pre>
  
  <p>And QualityBox, which extends that:</p>
  
  <pre><code>public class QualityBox extends ModeBox&lt;String&gt; {
      public QualityBox() {
          setItems(FXCollections.observableArrayList("Very Low", "Low", "Medium", "High", "Very High"));
      }
  }
  </code></pre>