/* * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.stage.Stage; /** * * @author Alexander Kouznetsov */ public class ChoiceBoxWidth extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { TextField textField = new TextField(); ObservableList cities = FXCollections.observableArrayList(); cities.addAll("Santa Clara", "Mountain View", "Palo Alto", "Sunnyvale"); ChoiceBox choiceBox = new ChoiceBox(cities); GridPane gridPane = new GridPane(); int rowIndex = 0; gridPane.addRow(rowIndex++, textField); gridPane.addRow(rowIndex++, choiceBox); GridPane.setHgrow(choiceBox, Priority.ALWAYS); Scene scene = new Scene(gridPane, 400, 300); stage.setScene(scene); stage.setVisible(true); } }