create JavaFX ComboBox - Java JavaFX

Java examples for JavaFX:ComboBox

Description

create JavaFX ComboBox

Demo Code


/*/*from   w w w.  jav a2  s .  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.ComboBox;
import javafx.util.StringConverter;

public class Main {
  static <T> ComboBox<T> createComboBox(final Cell<T> cell, final ObservableList<T> items,
      final ObjectProperty<StringConverter<T>> converter) {
    ComboBox<T> comboBox = new ComboBox<T>(items);
    comboBox.converterProperty().bind(converter);
    comboBox.setMaxWidth(Double.MAX_VALUE);
    comboBox.getSelectionModel().selectedItemProperty().addListener((ov, oldValue, newValue) -> {
      if (cell.isEditing()) {
        cell.commitEdit(newValue);
      }
    });
    return comboBox;
  }
}

Related Tutorials