你如何使用JavaFX监听在TextField中完成的鼠标粘贴? [英] How do you listen for mouse paste done in a TextField using JavaFX?
问题描述
将文本复制到剪贴板,右键单击文本字段并按粘贴,是否有一种方法可以在粘贴时点击?或者更确切地说,在以这种方式粘贴某些内容后,字段中的输入文本已更改。因为这些在这种特殊情况下不起作用:
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()
推荐答案
粘贴功能在 TextInputControl <中实现/ code> TextField
的超类control / TextInputControl.html#paste--rel =nofollow noreferrer> public void paste()
。因此,虽然它不是真正的事件驱动或MVC方法,但您可以通过覆盖此方法来响应粘贴操作(无论是通过鼠标或键盘快捷键调用,通常是ctrl-V):
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");
}
}
这篇关于你如何使用JavaFX监听在TextField中完成的鼠标粘贴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!