3 回答
TA贡献1830条经验 获得超3个赞
这似乎是修复JDK-8117199 的结果。该修复程序将以下内容添加到LabeledSkinBase#updateChildren():
// RT-19851 Only setMouseTransparent(true) for an ImageView. This allows the button
// to be picked regardless of the changing images on top of it.
if (graphic instanceof ImageView) {
graphic.setMouseTransparent(true);
}
如您所见,当Labeled控件的图形为 an 时,ImageView它被设置为鼠标透明。一种解决方法是将ImageView背面的鼠标透明度设置为 false。
ImageView view = new ImageView();
view.mouseTransparentProperty().addListener((observable, oldVal, newVal) -> {
if (newVal) {
view.setMouseTransparent(false);
}
});
由于您没有使用 CSS 根据悬停/武装状态更改图像,因此不应导致与错误相关的问题。不过,我会很谨慎;以防万一。
@fabian 提到的更好的解决方法是将 包装ImageView在其他一些Node(例如 a Pane)中。
Label customLabel = new Label(labelText, new Pane(removeImageView));
这使得图形 aPane这意味着不会发生特殊ImageView处理updateChildren()。
TA贡献2037条经验 获得超6个赞
处理这种情况的一种方法是使用HBox. 而不是传递ImageView到Label的构造函数集ImageView和Label作为子节点HBox
ImageView removeImageView = new ImageView(image);
Label customLabel = new Label("rito");
customLabel.setFont(Font.font("Arial", FontWeight.BOLD, 20));
HBox hbox = new HBox(removeImageView,customLabel);
root.getChildren().add(hbox);
removeImageView.setOnMouseClicked(e->{
System.out.println("ImageView clicked");
});
customLabel.setOnMouseClicked(e->{
System.out.println("Lable clicked");
});
添加回答
举报