我想使用答案中建议的解决方案:Prevent an accordion in JavaFX from collapsing,以防止JavaFX中的Accordion完全崩溃 .
我的问题是:为什么在expandedPaneProperty上添加的监听器使用Platform.runLater来调用setCollapsible(false)?
实际上,如果我删除Platform.runLater,在折叠/展开窗格后,它们的内容会因某种原因消失 . 那么为什么runLater会解决这个问题呢?
我想使用答案中建议的解决方案:Prevent an accordion in JavaFX from collapsing,以防止JavaFX中的Accordion完全崩溃 .
我的问题是:为什么在expandedPaneProperty上添加的监听器使用Platform.runLater来调用setCollapsible(false)?
实际上,如果我删除Platform.runLater,在折叠/展开窗格后,它们的内容会因某种原因消失 . 那么为什么runLater会解决这个问题呢?
1 回答
ChangeListener <T>的documentation表示:
In general is is considered bad practice to modify the observed value in this method.
这种方法指的是:
RunLater 确保Pane将在JavaFX应用程序线程的 next 运行中进行修改,因此在安全的情况下进行修改 .