package javafx.scene.control.test; import java.util.Arrays; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.geometry.Insets; import javafx.geometry.Orientation; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; import javafx.scene.layout.FlowPane; import javafx.scene.paint.Color; import javafx.stage.Stage; public class ChoiceBoxTest extends Application { @Override public void start(Stage stage) { stage.setTitle("ChoiceBox Test"); stage.setWidth(640); stage.setHeight(480); Scene scene = new Scene(new Group()); scene.setFill(Color.GHOSTWHITE); FlowPane root = new FlowPane(); root.setOrientation(Orientation.VERTICAL); scene.setRoot(root); root.setPadding(new Insets(8, 8, 8, 8)); root.setVgap(8); String[] items = {"A", "B", "C"}; ChoiceBox choiceBox = new ChoiceBox(); root.getChildren().add(choiceBox); choiceBox.setItems(FXCollections.observableList(Arrays.asList(items))); // NOTE One of these should clear the selection choiceBox.getSelectionModel().clearSelection(); choiceBox.getSelectionModel().select(null); choiceBox.getSelectionModel().select(-1); stage.setScene(scene); stage.setVisible(true); } public static void main(String[] args) { Application.launch(ChoiceBoxTest.class, args); } }