OptionComboBox
extends XComboBox and has an embedded menu-button which can be
configured to act as regular button. Each control with such an option button implements the interface OptionControl
.
OptionComboBox#getMenuItems()
can be used to add/remove menu items.
The screenshot was taken from OptionComboBoxDemo - the Demo can be downloaded from the link below.
OptionComboBox combo = new OptionComboBox<>(FXCollections.observableArrayList("John Doe", "John Meyer", "John Williams"));
CheckMenuItem mi = new CheckMenuItem("Item A");
mi.setSelected(true);
combo.getMenuItems().add(mi);
combo.getMenuItems().add(new SeparatorMenuItem());
combo.getMenuItems().add(new CheckMenuItem("Item B"));
combo.getMenuItems().add(new CheckMenuItem("Item C"));
combo.setPromptText("Username");
combo.setEditable(true);
combo.setOnAction((evt) -> System.out.println("Action"));
//combo.setClearButtonPosition(HPos.LEFT);
combo.setPrefWidth(250);
centerPane.getChildren().add(combo);