public MultiLabelToggle(Collection<E> c, Function<E, String> stringer, E initialElement) { super("multi-label-toggle"); Validate.argument(c.size() > 1, "a multilabeltoggle requires at least 2 element"); Validate.argument( c.contains(initialElement), "initialElement(%s) must be a part of the supplied collection(%s)", initialElement, c); elements = new ArrayList<>(c); labels = makeLabels(elements, stringer); selectedBackground.setHeight(labels.get(0).Height.get() + 2 * selectionBackgroundPadding); selectedBackground.setWidth(labels.get(elements.indexOf(initialElement)).Width.get()); selectedBackground.setX(calculateInitialX(initialElement)); addChildren(selectedBackground, box); CurrentSelection = new SimpleObjectProperty<E>(initialElement) { @Override protected void invalidated() { final E value = get(); final int index = elements.indexOf(value); Validate.argument( index >= 0, "the supplied value(%s) is not part of the valid values(%s)", value, elements); setValueInternal(labels.get(index)); }; }; }