OptionControlBox

OptionControlBox is a container mainly used to easily create a custom OptionControl. The box can hold one ore more controls provides a menu-button and a clear-button to manage the added controls. OptionControlBox implements the OptionControl interface. Use #setNodes(Node...) to add your controls to the box. OptionComboBox#getMenuItems() can be used to add/remove menu items. The menu-button can be configured to act as regular button - in this case an action event handler can be set which will be called when the option button is pressed.

The screenshots have been taken from OptionControlBoxDemo - the Demo can be downloaded from the link below. At least two methods have to be implemented by yourself. OptionControlBox#getProperty() has to return the observable value property of the child control. OptionControlBox#clearValue() has to clear/empty the value. In some cases it's required to override OptionControlBox#isEmpty() - e.g. when you have to use more than one control.

ComboBox combo = new ComboBox<>(FXCollections.observableArrayList("Combo Item 1", "Combo Item 2", "Combo Item 3"));
combo.getSelectionModel().select(1);
OptionControlBox> optionBox = new OptionControlBox>(){
  @Override
  public void clearValue(){
    combo.setValue(null);
  }
  @Override
  public ObservableValue getProperty(){
    return combo.valueProperty();
  }
};
optionBox.setNodes(combo);
    
CheckMenuItem mi = new CheckMenuItem("Item A");
mi.setSelected(true);
optionBox.getMenuItems().add(mi);
optionBox.getMenuItems().add(new SeparatorMenuItem());
optionBox.getMenuItems().add(new CheckMenuItem("Item B"));
optionBox.getMenuItems().add(new CheckMenuItem("Item C"));

optionBox.setOnAction((evt) -> System.out.println("Action"));        
centerPane.getChildren().add(optionBox);
The OptionControlBox with a ComboBox as child node.

The OptionControlBox with two Sliders as child nodes.

See also

Download OptionControlBox Demo
CSS Reference - OptionControlBox