Javafx:ListView禁用列表的指定元素 [英] Javafx: ListView disable a specified element of the list

查看:252
本文介绍了Javafx:ListView禁用列表的指定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ListView< String> ,我想要禁用列表中的一个指定元素,以使用户无法选择。有没有办法只禁用一个指定的元素进行选择?

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?

推荐答案

感谢@ user1803551和@James_D我可以解决问题,这是sollution:

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

            };
        }
    });

这篇关于Javafx:ListView禁用列表的指定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆