当按住键时,Swing中的文本输入字段在OS X上停止工作 [英] Text input fields in Swing stop working on OS X when holding keys down

查看:155
本文介绍了当按住键时,Swing中的文本输入字段在OS X上停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X Yosemite上发现了Swing文本输入字段的一个奇怪问题(使用Oracle JDK 8)。当我在文本输入字段具有焦点时按住任何字母或数字键时,我之后可以不再在当前JFrame的任何字段中输入任何内容。然后我必须关闭框架并重新打开它才能再次输入文本。

I discovered a strange problem with Swing text input fields on OS X Yosemite (using Oracle JDK 8). When I hold down any letter or number key while a text input field has the focus, I can afterwards no longer enter anything in any field of the current JFrame. I then have to close the frame and reopen it to be able again to enter text.

OS X中的默认行为是调出一个小菜单来选择特殊字母从按住一个键很长一段时间。我猜Swing输入确实存在问题。

The default behaviour in OS X is to bring up a small menu to choose special letters from when holding down a key for a longer time. I guess that the Swing inputs do have a problem with that.

其他人是否也注意到这一点,是否有解决此问题的方法?

Did anyone else also notice this, and is there a solution to this problem?

编辑:我了解到可以通过将标志 ApplePressAndHoldEnabled 设置为来禁用字符重音菜单false

I've learned that it is possible to disable the character accent menu by setting the flag ApplePressAndHoldEnabled to false.

defaults write -g ApplePressAndHoldEnabled -bool false

但是,我想在Java中以编程方式解决这个问题,因此文本输入字段也适用于使用我的软件的其他人。

However, I would like to solve this programmatically within Java, so that text input fields also work for other people using my software.

谢谢

推荐答案

我一直有这个确切的问题。我很沮丧,我的JFrame中的所有输入文本字段都会停止工作。直到今天才发现它与苹果的重音字符弹出相关。对我来说,这个问题只发生在我长按其中一个带有相关重音字符的键(例如:a,c,e,u,n,...)时,而帧中的焦点位于一个组件上没有文字输入(例如按钮或面板)。
仍在寻找一个合适的解决方案,以便在程序本身内以编程方式修复它,但这是我意外发现的一种解决方法:

I have been having this exact issue for quite a while. I was frustrated that suddenly all input text fields in my JFrame would stop working. It was only today that I found it to be related the apple's popup for accented characters. For me the issue only happens when I long press one of the keys that has associated accented characters (for example: a, c, e, u, n, ...) while the focus in the frame is on one the components that doesn't have a text input (e.g. a button or a panel). Still looking for a proper solution to fix it programmatically within in the program itself, but here is a workaround I accidentally found:

每当问题发生时,键停止工作,我首先点击帧中的任何文本字段使其聚焦,然后我按住任意一个带有重音弹出键(例如a键),直到弹出显示。然后我只是在所有按键重新开始工作后点击逃生并从那里开始。

Whenever the issue happens and the keys stop working, I first click on any "text field" in the frame to make it focused, then I hold any one of those keys with accent popup (e.g. "a" key), until the popup show. Then I just hit escape and from there after all the keys start working again.

奇怪的是,一旦我经历了这一次,问题就再也不会发生了框架,直到下一次关闭和打开框架。

Strangely, once I go through this once, the issue doesn't ever happen again on that frame until the next time the frame is closed and opened.

这篇关于当按住键时,Swing中的文本输入字段在OS X上停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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