简体   繁体   中英

Using Platform.runLater to disable collapsing an Accordion in JavaFX

I want to use the solution suggested in the answer at: Prevent an accordion in JavaFX from collapsing in order to prevent the Accordion in JavaFX from entirely collapsing.

My question is: why does the listener added on the expandedPaneProperty use Platform.runLater to call setCollapsible(false)?

Indeed, if I remove Platform.runLater, after collapsing/expanding the panes, their content disappears for some reason. So why does the runLater solve that problem?

The documentation of ChangeListener< T> states, that:

In general is is considered bad practice to modify the observed value in this method.

Where this method refers to:

void changed(ObservableValue<? extends T> observable, T oldValue, T newValue);

RunLater ensures, that the Pane will be modiffied on the next run of the JavaFX Application Thread and so making modifications when it is safe to do them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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