📜  用于组合框的 java fx 自定义单元工厂 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:27             🧑  作者: Mango

代码示例1
@FXML ComboBox cmbUserIds;

Callback, ListCell> cellFactory = new Callback, ListCell>() {

    @Override
    public ListCell call(ListView l) {
        return new ListCell() {

            @Override
            protected void updateItem(User item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                } else {
                    setText(item.getId() + "    " + item.getName());
                }
            }
        } ;
    }
}

// Just set the button cell here:
cmbUserIds.setButtonCell(cellFactory.call(null));
cmbUserIds.setCellFactory(cellFactory);