当前位置: 首页>>代码示例>>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;未经允许,请勿转载。