问题
Copy text into your clipboard, right click text field and press "paste", is there a way how to listen when paste was clicked? Or rather that input text in the field changed after something was pasted this way. Because these do not work in this particular case:
setOnKeyReleased()
setOnInputMethodTextChanged()
回答1:
The "paste" functionality is implemented in the TextInputControl
superclass of TextField
in public void paste(). So, while it's not really an event-driven or MVC approach, you can react to a "paste" action (whether it's invoked by mouse or keyboard shortcut, typically ctrl-V) by overriding this method:
TextField tf = new TextField() {
@Override
public void paste() {
super.paste();
System.out.println("text pasted in");
}
}
来源:https://stackoverflow.com/questions/41762158/how-do-you-listen-for-mouse-paste-done-in-a-textfield-using-javafx