在JavaFX中,如何绑定两个列表视图以使它们的selectedIndex始终相同?
我有两个(或更多)并排的 ListView。我需要它们作为一个整体,以便每个的选定索引始终相同。
I have two (or more) ListView's that are side by side. I need them to act as one so the selected index of each is always the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可行:),也许吧。
This should work :), maybe.
“与逆绑定”似乎是一个选项:
仅适用于简单表达式。任何更复杂的事情都会生成警告/错误。
但这不是因为 ListView 的 selectedIndex 是公共读取的(感谢更正)。
您必须这样做:
您可能还想在这里和那里添加一些 if 以避免额外的 select() 调用。
"bind with inverse" seems to be an option:
works only for simple expressions. anything more complex will generate a warning/error.
Except that it isn't because of ListView's selectedIndex is public-read (thaks for the correction).
You will have to do it like this:
You also may want to add some ifs here and there to avoid extra select() calls.