/** * Copyright (c) 2008, 2012 Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ import javafx.application.Application; import javafx.geometry.Side; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.control.ChoiceBox; /** * A sample that shows a choice box with several options. The ChoiceBox control * displays a default or current selection, with an icon to click that expands * the list for a selection. * * @see javafx.scene.control.ChoiceBox @related controls/buttons/CheckBoxes * @related controls/buttons/ToggleButton @related controls/toolbar/ToolBar */ public class ChoiceBoxSample extends Application { private void init(Stage primaryStage) { Group root = new Group(); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 150, 100)); ChoiceBox cb = new ChoiceBox(); cb.getItems().addAll("Dog", "Horse", "Cat", "Monkey", "Rabbit"); cb.getSelectionModel().select("Horse"); root.getChildren().add(cb); } public double getSampleWidth() { return 150; } public double getSampleHeight() { return 100; } @Override public void start(Stage primaryStage) throws Exception { init(primaryStage); primaryStage.show(); } public static void main(String[] args) { launch(args); } }