如何在fxml中为图像设置事件处理程序。我写了下面这3个图像,我想单击它们,并调用我已经在我的控制器类中创建的函数。我已经尝试过使用鼠标和onAction,他们都不会工作。如何在FXML(Javafx Project)中设置图像监听器?
<ImageView fitHeight="31.0" fitWidth="29.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="0" >
<image >
<Image url="@/views/add.png" />
</image>
</ImageView>
<ImageView fitHeight="31.0" fitWidth="29.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="1">
<image>
<Image url="@/views/remove.png" />
</image>
</ImageView>
<ImageView fitHeight="31.0" fitWidth="29.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
<image>
<Image url="@/views/edit.png" />
</image>
</ImageView>
我也检出了其他帖子,但他们都说如何做到这一点,当图像的实用定义。 任何建议表示赞赏。
为什么你不选择使用按钮,为CSS图像样式?我认为使用ImageView来达到这个目的将是一个长期的矫枉过正。 – iMan
@iMan是否可以简单地将css添加到fxml内联?如果是的话,我会赞赏一个简单的例子:) –
我已经找到它;)示例: –