java—无法从treeview选择模型上的listchangelistener获得预期结果

ss2ws0br  于 2021-07-08  发布在  Java
关注(0)|答案(0)|浏览(163)

我有以下测试代码:

tvNodes.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    tvNodes.getSelectionModel().getSelectedItems().addListener(new ListChangeListener<TreeItem<Node>>() {
                @Override
                public void onChanged(Change<? extends TreeItem<Node>> c) {
                    while (c.next()) {
                        log.debug("From {} To {} (Removed: {}, Added: {}, Replaced: {}, List: {})", c.getFrom(), c.getTo(), c.wasRemoved(), c.wasAdded(), c.wasReplaced(), c.getList());
                        if (c.wasAdded()) {
                            for (var added : c.getAddedSubList()) {
                                log.debug("\tADDED ITEM: {}", added);
                            }
                        }
                        if (c.wasRemoved()) {
                            for (var removed : c.getRemoved()) {
                                log.debug("\tREMOVED ITEM: {} ({})", removed.getValue(), c.getRemovedSize());
                            }
                        }
                        if (c.wasReplaced()) {
                            log.debug("\tWAS REPLACED {} to {}", c.getFrom(), c.getTo());
                        }
                        if (c.wasPermutated()) {
                            log.debug("\tWAS PERMUTATED {} to {}", c.getFrom(), c.getTo());
                        }
                    }
                }
            });

从“完整选择”过渡到“单项选择”时(圈8)
发件人:

收件人:

我希望收到两个更改事件(删除)。第一个事件将项目从圆(3)返回到圆(7),第二个事件将项目从圆(9)返回到圆(11)。
实际结果:
第一个事件按预期返回前半部分,但第二个事件返回第4、5、6项,而不是第9、10和11项。

From 0 To 0 (Removed: true, Added: false, Replaced: false, List: [TreeItem [ value: Circle (8) ]])
    REMOVED ITEM: Circle (3) (5)
    REMOVED ITEM: Circle (4) (5)
    REMOVED ITEM: Circle (5) (5)
    REMOVED ITEM: Circle (6) (5)
    REMOVED ITEM: Circle (7) (5)
From 1 To 1 (Removed: true, Added: false, Replaced: false, List: [TreeItem [ value: Circle (8) ]])
    REMOVED ITEM: Circle (4) (3)
    REMOVED ITEM: Circle (5) (3)
    REMOVED ITEM: Circle (6) (3)

这是一个错误还是我处理结果不正确?我目前正在使用jdk15.0.036和openjfx15

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题