如何防止TreeItem选择? [英] How to prevent TreeItem selection?

查看:66
本文介绍了如何防止TreeItem选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TreeTableView(JavaFX 8).有一些树节点,必须禁用这些树节点才能进行选择.我曾尝试过选择活动,但没有成功.请找到下面的代码以获取更多信息.

I'm working with a TreeTableView (JavaFX 8). There are some tree nodes, which have to be disabled for selection. I had tried the selection event, but it doesn't work. Please find the below code for more information.

treeTableView.getSelectionModel().selectedItemProperty().addListener(
                (observable, oldValue, newValue) ->
    {
        // utility node
        if(newValue.getValue() instanceof UtilityRoot )
        {
            return;
        }  
    }
);

如何防止任何TreeItems通过鼠标和键盘进行选择?

How can I prevent some TreeItems from any mouse and keyboard selection?

推荐答案

您尝试实现的目标无法正常工作,因为它只是添加了一个侦听器,以便在所选项目发生更改时随时通知您,这对于您而言已经太迟了以防止在调用侦听器之前发生选择.

What you try to achieve cannot work as it simply adds a listener to be notified any time the selected item changes which is already too late in your case as you want to prevent the selection which happens before calling the listeners.

默认情况下,您可以指定是否要使用treeTableView.getSelectionModel().setSelectionMode(selectionMode)选择SINGLEMULTUPLE模式,以及是否允许使用treeeTableView.getSelectionModel().setCellSelectionEnabled(enabled)选择单元格.

By default you can specify if you want the SINGLE or MULTUPLE selection mode using treeTableView.getSelectionModel().setSelectionMode(selectionMode) and if you want to allow cell selection using treeeTableView.getSelectionModel().setCellSelectionEnabled(enabled).

  • SelectionMode.SINGLE和单元格选择enabled:启用对表格中单个单元格的选择.
  • SelectionMode.SINGLE和单元格选择disabled:启用对表中单行的选择.
  • SelectionMode. MULTUPLE和单元格选择enabled:启用对多行中多个单元格的选择.
  • SelectionMode. MULTUPLE和单元格选择disabled:允许选择表中的几行.
  • SelectionMode.SINGLE and cell selection enabled: Enables selection of a single cell in the table.
  • SelectionMode.SINGLE and cell selection disabled: Enables selection of a single row in the table.
  • SelectionMode. MULTUPLE and cell selection enabled: Enables selection of several cells in several rows.
  • SelectionMode. MULTUPLE and cell selection disabled: Enables selection of several rows in the table.

如果这对您来说不够好,则需要实现自己的

If it is not good enough for you, you will need to implement your own TreeTableViewSelectionModel and set it using setSelectionModel(TreeTableView.TreeTableViewSelectionModel<S> value).

这篇关于如何防止TreeItem选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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