A simple implementation is:
public class MyApplication extends Application {
private final List<String> commands = new ArrayList<>();
@Override
public void start(Stage primaryStage) {
VBox commandToggles = new VBox();
commandToggles.getChildren().add(createCommandToggle("Command 1", "exec1"));
commandToggles.getChildren().add(createCommandToggle("Command 2", "exec2"));
commandToggles.getChildren().add(createCommandToggle("Command 3", "exec3"));
// ...
Button runButton = new Button("Run");
runButton.setOnAction(e -> {
ProcessBuilder pb = new ProcessBuilder(commands);
// ...
});
// ...
}
private ToggleButton createCommandToggle(String text, String executable) {
ToggleButton button = new ToggleButton(text);
button.selectedProperty().addListener((obs, wasSelected, isSelected) -> {
if (isSelected) {
commands.add(executable);
} else {
commands.remove(executable);
}
}
return button ;
}
}
As @Valette_Renoux suggests, you can refine this by encapsulating the text for the button and the executable command in an enum, and replace the list with an EnumSet. This makes building the toggle buttons a little less repetitive (though you might need just a little more work in the runButton handler to extract the commands).