简体   繁体   English

如何检测用户何时在Java中键入jTextpane

[英]How to detect when user finished typing in jTextpane in Java

I have a document which is inside a jTextPane and it includes some components as labels in it. 我在jTextPane有一个文档,它包含一些组件作为标签。 When user adds text in the document by tying, the addresses of components change, so I have to run a method after user finished typing to reread all the component places at least only the ones that are after the caretPosition.is there any way to detect when user finished typing in jTextpane to run my update function. 当用户通过绑定在文档中添加文本时,组件的地址会发生变化,因此我必须在用户完成键入操作后运行一种方法,以重新读取所有组件位置,至少仅重读caretPosition之后的那些位置。有什么方法可以检测到当用户完成输入jTextpane以运行我的更新功能时。 If I run it each time after every key pressed, it takes a long time for inserting each letter while typing. 如果我在每次按下每个键后都运行它,那么键入时插入每个字母会花费很长时间。

Consider setting the JTextPane's inputVerifier to an instance of your own subclass of InputVerifier . 考虑将JTextPane的inputVerifier设置为您自己的InputVerifier子类的实例。 This has the advantage that you can set some controls (such as a "Cancel" button) to refrain from triggering it, using setVerifyInputWhenFocusTarget . 这样的好处是,您可以使用setVerifyInputWhenFocusTarget设置一些控件(例如“取消”按钮)以免触发它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM