如何了解 Swing 击键处理的内部原理

发布于 2024-11-17 22:04:36 字数 677 浏览 5 评论 0原文

摇摆可能是一个令人沮丧的野兽。特别是如果您试图用它来设计一个与 Swing 设计者在设计 Swing 时使用的假设“背道而驰”的应用程序。我们的要求是将功能分配给非常规的击键。昨天,问题是 JComboBoxJScrollPane 将 PageUp 和 PageDown 之类的键视为“导航键”,并抓住了这些键,尽管我们尝试将这些组件重新映射到其他用途有焦点。你可能会说,这是糟糕的设计,但这是我们的要求。甚至有特殊的键盘带有指示这些功能重新映射的标签,我们必须满足这些要求。这就是生活。

今天,出现了另一个问题,即 JTextPane 似乎在获得焦点时抓住了 F6 键。当其他组件获得焦点时,这不是问题。搞什么?

因此,我的问题很简单:是否有任何文档说明每种类型的 Swing 组件在普通 InputMap/ActionMap 系统之外抓取和放置哪些击键,敦促应用程序级程序员遵循?我知道这进一步取决于 LookAndFeel,并且 Motif 中发生的情况可能与 Metal 等中发生的情况不同。深入到这个级别,这些东西是否记录在任何地方?我想知道这一点,这样我可能一开始就知道我的问题出在哪里,而不是一次学习这个。如果我知道问题出在哪里,我就知道如何解决它们。但我有源代码、java 文档,但我只是不知道去哪里找。

Swing can be a frustrating beast. Especially if you are trying to design an application with it that goes "against the grain" of the assumptions that the Swing designers used in designing Swing. We have requirements that assign functionality to keystrokes that are way out of the normal. Yesterday, the issue was that JComboBox and JScrollPane considered keys like PageUp and PageDown "navigation keys" and grabbed these in spite of our attempts to remap them to other uses when such components had focus. You might say, that's poor design, but those are our requirements. There are even special keyboard that have labels indicating these functional remappings and we have to meet those. Such is life.

Today, another issue has popped up that a JTextPane seems to be grabbing the F6 key when it has focus. When other components have focus, not a problem. WTF?

And so, my question is simply this: Is there any documentation on what keystrokes each type of Swing component is grabbing and placing outside the normal InputMap/ActionMap system that application level programmers are urged to follow? I know this depends further on the LookAndFeel, and that what happens in Motif may be different than what happens in Metal, etc. Still, even drilling down to this level, is this stuff documented anywhere? I would like to know this so I might know at the start where my problems are going to lie instead of learning this one at a time. If I know where the problems are I know how to work around them. But I have source code, java docs, and I just don't know where to look.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷路的信 2024-11-24 22:04:36

是否有任何文档说明每种类型的 Swing 组件在正常的 InputMap/ActionMap 系统之外抓取和放置哪些击键,敦促应用程序级程序员遵循?

据我所知,没有任何文档。

也许按键绑定列表会对您有所帮助。

Is there any documentation on what keystrokes each type of Swing component is grabbing and placing outside the normal InputMap/ActionMap system that application level programmers are urged to follow?

No documentation that I'm aware of.

Maybe Key Bindings list will help you out.

Oo萌小芽oO 2024-11-24 22:04:36

文章键盘面板链接到相关教程和演示一个例子。

The article Keypad Panel links to related tutorials and shows an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文