这是我的代码:
@FXML private TextArea txtconfig;
public void handleMousePressed(MouseEvent mouseEvent) {
txtconfig.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("PRESSED");
}
});
}
在FXML中:
TextArea fx:id="txtconfig" style="-fx-font-size:10pt; -fx-font-family:Consolas"
maxWidth="Infinity" maxHeight="Infinity" VBox.vgrow="ALWAYS"
onMousePressed="#handleMousePressed"/>
然而,setOnMouseClicked正在努力保持一切相同。只有onMousePressed在FXML中更改为onMouseClicked。
public void handleMouseClicked(MouseEvent mouseEvent) {
txtconfig.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("Clicked");
}
});
}
答案 0 :(得分:0)
正如this answer中所建议的那样,如果你确实需要ÈventFilter
事件(这似乎是由控件本身使用),你可以安装MousePressed
:
txtconfig.addEventFilter(
MouseEvent.MOUSE_PRESSED,
new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
System.out.println("PRESSED");
}
}
);