Javafx: ListView disable a specified element of the list

浪子不回头ぞ 提交于 2019-12-12 20:38:31

问题


I have a ListView<String> and I want to disable one specified element of the list, to become unselectable for the user. Is there a way to disable just one specified element for selection?


回答1:


Thanks to @user1803551 and @James_D i could solve the problem, here is the sollution:

listView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override 
        public ListCell<String> call(ListView<String> param) {
            return new ListCell<String>() {
                @Override 
                protected void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if ("Orange".equals(item)) {
                        setDisable(true);
                    } else {
                        setDisable(false);
                    }
                    setText(item);
                }

            };
        }
    });


来源:https://stackoverflow.com/questions/43998613/javafx-listview-disable-a-specified-element-of-the-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!