OptionTextField
extends XTextField and has an embedded menu-button which can be
configured to act as regular button. OptionTextField#getMenuItems()
can be used to add/remove menu items. Each
control with such an option button implements the interface OptionControl
.
The screenshot was taken from OptionTextFieldDemo - the Demo can be downloaded from the link below.
OptionTextField field = new OptionTextField("JohnDoe");
CheckMenuItem mi = new CheckMenuItem("Item A");
mi.setSelected(true);
field.getMenuItems().add(mi);
field.getMenuItems().add(new SeparatorMenuItem());
field.getMenuItems().add(new CheckMenuItem("Item B"));
field.getMenuItems().add(new CheckMenuItem("Item C"));
field.setPromptText("Username");
field.setOnAction((evt) -> System.out.println("Action"));
field.setPrefWidth(250);
centerPane.getChildren().add(field);