在FXML中将RadioMenuItem添加到ToggleGroup

spi*_*lot 11 javafx menuitem radio-button fxml

在我的FXML内部,我有这个:

<fx:define>
  <ToggleGroup fx:id="toggleGroup1"/>  
</fx:define>
<Menu fx:id="toggleProofView" text="%proofView">
  <items>
    <RadioMenuItem text="%hide"
                   selected="true"
                   onAction="#handleLoadComponent"
                   toggleGroup="toggleGroup1"/>`
Run Code Online (Sandbox Code Playgroud)

不知怎的,我得到了错误:

Unable to coerce toggleGroup1 to class javafx.scene.control.ToggleGroup

但为什么?

我要做的是创建一个Menu包含其中几个RadioMenuItem都在同一个ToggleGroup中的东西.如何将它们添加到FXML文件中的切换组?

spi*_*lot 13

你必须写

toggleGroup="$toggleGroup1"
Run Code Online (Sandbox Code Playgroud)