Java - 使文本框不会失去焦点 [英] Java - making a textbox not lose focus

查看:41
本文介绍了Java - 使文本框不会失去焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个不同的输入文本框,你可以在其中输入命令,按回车键,然后它会调出一些信息.我有几个不同的文本框(适用于信息的不同部分).当我按下 Enter 键时,它还会将焦点移到下一个输入框上.我该如何阻止?我不能简单地在 keyevent 类中使用消耗()方法,因为这会完全阻止回车键,这不是我想要的

I have a few different input textboxes which you can enter a command into, press enter, and then it pulls up some information. I have a few different textboxes who (applying to different parts of information). When I press enter, it also moves the focus onto the next input box. How do I stop this? I can't simply use the consume() method in the keyevent class since that would entirely block the enter key, which is not what I want

推荐答案

实际上,我刚刚发现如何解决这个问题.我使用了属于 Container 的方法 requestFocus()(参见 http://www.javaworld.com/javaworld/jw-07-1998/jw-07-swing-focus.html).在每个元素中,我将此行添加到 keyEvent 操作的末尾,并且效果很好!

Actually, I just found out how to fix this issue. I used the method belonging to Container called requestFocus() (see http://www.javaworld.com/javaworld/jw-07-1998/jw-07-swing-focus.html). In each element I added this line to the end of the keyEvent action and it worked perfectly!

这篇关于Java - 使文本框不会失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆