【发布时间】:2016-08-08 20:11:42
【问题描述】:
在我的 JAVAFX 应用程序中,我在 tilepane 中有图像视图,我想实现类似于 android 中图像的多选功能。我尝试在单击事件时向 imageView 添加边框样式,但这没有用。有什么办法可以做到这一点。
【问题讨论】:
标签: java imageview javafx-2 multi-select javafx-css
在我的 JAVAFX 应用程序中,我在 tilepane 中有图像视图,我想实现类似于 android 中图像的多选功能。我尝试在单击事件时向 imageView 添加边框样式,但这没有用。有什么办法可以做到这一点。
【问题讨论】:
标签: java imageview javafx-2 multi-select javafx-css
您可以将Image 嵌入到JavaFX Button 中,并设置Button 的OnAction 方法:
imageButton.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent e) {
System.out.println("Changing the color of the button's border :");
imageButton.setStyle("-fx-border-color:blue;");
System.out.println("For further reference, you can save the button or the image in a TreeSet:");
treeSet.add(imageButton);
}
});
如果一个简单的点击就足以选择图像,你可以像上面那样定义Button的OnAction方法。但是,如果您需要长按(Android 样式中的长按)来更改图像的选择状态,您可以在此处找到有关“长按”的更多信息:how to achieve javafx mouse event "push and hold"?。
【讨论】: