Java examples for JavaFX:ChoiceBox
create JavaFX Choice Box
/*// w ww . j ava 2s . c om * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ //package com.java2s; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import javafx.scene.control.Cell; import javafx.scene.control.ChoiceBox; import javafx.util.StringConverter; public class Main { static <T> ChoiceBox<T> createChoiceBox(final Cell<T> cell, final ObservableList<T> items, final ObjectProperty<StringConverter<T>> converter) { ChoiceBox<T> choiceBox = new ChoiceBox<T>(items); choiceBox.setMaxWidth(Double.MAX_VALUE); choiceBox.converterProperty().bind(converter); choiceBox.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> { if (cell.isEditing()) { cell.commitEdit(newValue); } }); return choiceBox; } }