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);
}
};
}
});