Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 JTextPane 集成,它应该对按键事件执行预定义的步骤。如果我手动输入,它似乎工作正常。但是出于测试目的,我必须在此集成上模拟按键事件。测试环境使得给定的 JTextPane 不会添加到任何其他控件。在将 JTextPane 的可见性和可编辑性设置为 true 并请求焦点后,我尝试使用 Robot 类。问题是我看不到任何按键事件的到来,并且 JTextPane 的内容仍然是空的。请给我一些建议。谢谢,
彼得
测试环境使得给定的 JTextPane 不会添加到任何其他控件
然后该组件在屏幕上不可见并且无法接受焦点,因此机器人将无法工作。
我不确定,但你也许可以使用
textPane.dispatchEvent(....).
或者,如果这不起作用,那么您可以使用:
textPane.getDocument().insertString(...);