在我的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文件中的切换组?
在我的 JavaFX 应用程序中,我使用 TreeView。单个 TreeItems 包含一个图像。不幸的是,该图像仅显示一次。

加载图像的代码如下所示。每次 TreeView 更改时都会调用它。这些Images 缓存在 a Map(“图标”)中。因此,ImageView每次都会创建一个新的。
public final ImageView getImage(final String imageConstant) {
final Image img;
if (icons.containsKey(imageConstant)) {
img = icons.get(imageConstant);
}
else {
if (isRunFromJAR) {
img = new Image("/path/" + imageConstant, iconSizeWidth,
iconSizeHeight, false, false);
}
else {
img = new Image(getClass().getResourceAsStream(imageConstant), iconSizeWidth,
iconSizeHeight, false, false);
}
icons.put(imageConstant, img);
}
return new ImageView(img);
Run Code Online (Sandbox Code Playgroud)
在updateItemmy TreeCells 的方法中,ImageView上面返回的内容存储到名为 的字段中icon。该字段在以下代码中使用,也来自updateItem: …