简体   繁体   English

JavaFX TabPane-更改一个选项卡,更新其他选项卡

[英]JavaFX TabPane - Change one tab, update the others

I have a TabPane with 10 tabs (each with its controller). 我有一个带有10个标签的TabPane(每个都有其控制器)。 In one of them I have a table 'categories' where the user can add / edit / delete categories. 在其中之一中,我有一个表“类别”,用户可以在其中添加/编辑/删除类别。 The other tabs have the same table 'categories', smaller, in read-only mode, where the user can only select categories. 其他选项卡在只读模式下具有相同的表“类别”,但较小,用户只能选择类别。 Then, when the table 'categories' is modified in the categories tab, what I want is for all other tables categories of the other tabs are updated. 然后,当在“类别”选项卡中修改表“类别”时,我想要的是对所有其他表的其他选项卡的类别进行更新。 What I thought is (not implemented yet), on the top panel to put a listener that detects tab changes and, when the user leaves the categories tab, check if changes have been made. 我想的是(尚未实现),在顶部面板上放置一个侦听器,该侦听器检测选项卡的更改,并在用户离开类别选项卡时检查是否进行了更改。 If so, call all the controllers involved to update their own tables of categories. 如果是这样,请调用所有涉及的控制器以更新其自己的类别表。

The question I have is, if there is a less cumbersome way to do this. 我的问题是,是否有一种不太麻烦的方法来做到这一点。 Something like sending a message 'table has been changed' and all the 'listeners' tabs of the message update their tables. 例如发送消息“表已更改”,消息的所有“侦听器”选项卡都会更新其表。 Similar to a locally JMS, not client-server. 类似于本地JMS,而不是客户端服务器。 Is there something like this messaging service that can be employed within the same application or the solution that I raised above is the most consistent? 是否有可以在同一应用程序中使用的类似此消息传递服务的东西,或者我上面提出的解决方案是最一致的? I think the question is more Java than JavaFX. 我认为问题在于Java比JavaFX更多。 Thanks a lot. 非常感谢。

The easiest way would be to hold the categories in an ObservableList at some top level (say in your Application sub class) and have all the tables share a reference to that list ( table.setItems(yourList) ). 最简单的方法是将类别保留在某个顶级的ObservableList中(例如,在Application子类中),并使所有表共享对该列表的引用( table.setItems(yourList) )。 Whenever a change is made in the categories tab, the other tabs will automatically reflect the change. 每当在类别选项卡中进行更改时,其他选项卡将自动反映更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM