在 javaFX 中单击图形时防止 TitledPane 打开
Prevent TitledPane from opening when the grapich is clicked, in javaFX
我向 TitledPane 添加了一个图形(一个图标),并在其上设置了一个 onMouseCliked
处理程序(以打开一个弹出窗口)。
此事件处理程序使用事件。
问题是,当我单击该图标时,弹出窗口打开,但 TitledPane 也被扩展。
我该如何防止这种情况发生?
public class MyPanel extends BorderPane{
@FXML
TitledPane titledPane;
PopOver popOver;
Text icon;
public MyPanel(){
//FXML injection
popOver = new PopOver(new MyPane());
icon = GlyphsDude.createIcon(FontAwesomeIcon.ANCHOR, "15");
icon.setOnMouseClicked(this::onIconClicked);
titledPane.setGraphic(icon);
}
public void onIconClicked(MouseEvent e){
popOver.show(icon);
e.consume();
}
}
我找到了解决方案:
我刚刚消费了 MOUSE_CLICKED
事件,TitledPane 也在处理 MOUSE_PRESSED
/MOUSE_RELEASED
事件。
我向 TitledPane 添加了一个图形(一个图标),并在其上设置了一个 onMouseCliked
处理程序(以打开一个弹出窗口)。
此事件处理程序使用事件。 问题是,当我单击该图标时,弹出窗口打开,但 TitledPane 也被扩展。
我该如何防止这种情况发生?
public class MyPanel extends BorderPane{
@FXML
TitledPane titledPane;
PopOver popOver;
Text icon;
public MyPanel(){
//FXML injection
popOver = new PopOver(new MyPane());
icon = GlyphsDude.createIcon(FontAwesomeIcon.ANCHOR, "15");
icon.setOnMouseClicked(this::onIconClicked);
titledPane.setGraphic(icon);
}
public void onIconClicked(MouseEvent e){
popOver.show(icon);
e.consume();
}
}
我找到了解决方案:
我刚刚消费了 MOUSE_CLICKED
事件,TitledPane 也在处理 MOUSE_PRESSED
/MOUSE_RELEASED
事件。