2007-11-09
用ActionListener处理在JTextField里按Enter事件
常常有这样的需求,填完一些JTextField后,直接按Enter键就执行动作,而不需要再按一下按钮。本来以为在加一个Keytyped事件的侦听器,然后读取输入的字符就可以确定了,但是试了几次都没有成功。后来查了一下JDK API,看到这样的话:
How the text field consumes VK_ENTER events depends on whether the text field has any action listeners. If so, then VK_ENTER results in the listeners getting an ActionEvent, and the VK_ENTER event is consumed. This is compatible with how AWT text fields handle VK_ENTER events. If the text field has no action listeners, then as of v 1.3 the VK_ENTER event is not consumed. Instead, the bindings of ancestor components are processed, which enables the default button feature of JFC/Swing to work.
看来是要用ActionLinstener, 如没有用的话,就会传给上层组件。
发表评论
- 浏览: 3152 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
最近加入圈子
链接
最新评论
-
优化jboss以提高性能
为何看不全,只显示一部分呢!?
-- by lenhome -
优化richfaces,给seam提 ...
受教了 3Q~
-- by 40020072 -
用htmlparser解析google搜 ...
因为,没有配置java_home,或者可以再cmd下运行。
-- by water84222 -
用htmlparser解析google搜 ...
为什么,我下载后的只有filterbuilder.cmd,而且双击后,没有任何反 ...
-- by water84222 -
通过Annotation和Struts2 ...
d
-- by evonli






评论排行榜