當前位置: 首頁>>代碼示例>>Java>>正文


Java ComboBox.setConverter方法代碼示例

本文整理匯總了Java中javafx.scene.control.ComboBox.setConverter方法的典型用法代碼示例。如果您正苦於以下問題:Java ComboBox.setConverter方法的具體用法?Java ComboBox.setConverter怎麽用?Java ComboBox.setConverter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.control.ComboBox的用法示例。


在下文中一共展示了ComboBox.setConverter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: TimeRangeFieldSkin

import javafx.scene.control.ComboBox; //導入方法依賴的package包/類
public TimeRangeFieldSkin(TimeRangeField control) {
    super(control);

    ComboBox<TimeRangeField.TimeRangeFieldValue> valuesComboBox = new ComboBox<>();
    valuesComboBox.setConverter(new TimeRangeFieldValueStringConverter());
    valuesComboBox.setItems(control.getValues());
    valuesComboBox.valueProperty().bindBidirectional(control.valueProperty());
    valuesComboBox.setVisibleRowCount(5);

    datePicker = new DatePicker();
    datePicker.getEditor().setPrefColumnCount(6);
    datePicker.valueProperty().bindBidirectional(control.onDateProperty());
    datePicker.managedProperty().bind(datePicker.visibleProperty());
    datePicker.setEditable(false);

    weekValueFactory = new IntegerSpinnerValueFactory(1, 52);
    weekValueFactory.valueProperty().addListener(obs -> control.setOnWeekNumber(weekValueFactory.getValue()));
    control.onWeekNumberProperty().addListener(obs -> {
        if (control.getOnWeekNumber() != null) {
            weekValueFactory.setValue(control.getOnWeekNumber());
        }
    });
    weekNumberSpinner = new Spinner<>();
    weekNumberSpinner.setValueFactory(weekValueFactory);
    weekNumberSpinner.managedProperty().bind(weekNumberSpinner.visibleProperty());
    weekNumberSpinner.setPrefWidth(70);

    monthYearValueFactory = new IntegerSpinnerValueFactory(1972, 3000);
    monthYearValueFactory.valueProperty().addListener(obs -> control.setMonthYear(monthYearValueFactory.getValue()));
    control.monthYearProperty().addListener(obs -> {
        if (control.getMonthYear() != null) {
            monthYearValueFactory.setValue(control.getMonthYear());
        }
    });

    monthYearSpinner = new Spinner<>();
    monthYearSpinner.getEditor().setPrefColumnCount(6);
    monthYearSpinner.setValueFactory(monthYearValueFactory);
    monthYearSpinner.managedProperty().bind(monthYearSpinner.visibleProperty());

    afterUnitsValueFactory = new IntegerSpinnerValueFactory(1, 500);
    afterUnitsValueFactory.valueProperty().addListener(obs -> control.setAfterUnits(afterUnitsValueFactory.getValue()));
    control.afterUnitsProperty().addListener(obs -> {
        if (control.getAfterUnits() != null) {
            afterUnitsValueFactory.setValue(control.getAfterUnits());
        }
    });
    afterUnitsSpinner = new Spinner<>();
    afterUnitsSpinner.getEditor().setPrefColumnCount(4);
    afterUnitsSpinner.setValueFactory(afterUnitsValueFactory);
    afterUnitsSpinner.managedProperty().bind(afterUnitsSpinner.visibleProperty());
    afterUnitsLabel = new Label();
    afterUnitsLabel.managedProperty().bind(afterUnitsLabel.visibleProperty());

    InvalidationListener listener = obs -> layout();
    control.viewTypeProperty().addListener(listener);
    control.valueProperty().addListener(listener);

    HBox container = new HBox(5, valuesComboBox, datePicker, weekNumberSpinner, monthYearSpinner, afterUnitsSpinner, afterUnitsLabel);
    container.setAlignment(Pos.CENTER_LEFT);
    HBox.setHgrow(valuesComboBox, Priority.ALWAYS);
    HBox.setHgrow(datePicker, Priority.SOMETIMES);

    getChildren().add(container);
    layout();
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:67,代碼來源:TimeRangeFieldSkin.java


注:本文中的javafx.scene.control.ComboBox.setConverter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。