发布一个KeyEvent到关注的组件 [英] Post a KeyEvent to the focused component
问题描述
发布按钮的最佳方式是按组件?我尝试使用机器人类,它正常工作。然而,这个类在一些Linux平台下有一些问题,所以我想知道什么是最好的Java唯一的方式来发布事件到一个组件。
What is the best way to post a Button Press to a component? I tried using the Robot class and it works, normally. However, this class has some problems under some Linux platforms, so I wonder what is the best Java-only way to post an event to a component.
在这种情况下当我按下一个按钮时,我想将退格事件发送到JTextField。
In this particular case, I want to post backspace events to a JTextField when I press a button.
编辑:我已经使用了Robot类。我解决了阻止这个类在Linux下正常工作的问题
推荐答案
我最终使用了机器人类,这是最简单的方法。问题是在我正在使用的特定Linux发行版中,Robot类的实例化将挂起虚拟机。查看日志文件,我发现java正在尝试加载一个不可用的DLL:
I ended up using the robot class, which was the easiest way after all. The problem is that in the specific Linux distro I was using, the instantiation of the Robot class would hang the Virtual Machine. Looking at the log files I found out that java was trying to load a DLL that wasn't available:
libXi.so.6
libXi.so.6
将该库添加到发行版后,我可以继续
After adding this library to the distro I was able to continue
这篇关于发布一个KeyEvent到关注的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!