Swing 组件的 ActionMap 中默认操作的名称是否标准化? [英] Are the names of default actions in Swing component's ActionMap standardized?

查看:20
本文介绍了Swing 组件的 ActionMap 中默认操作的名称是否标准化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像 JSlider 这样的标准 Swing 组件,但我想稍微调整输入贴图.默认输入图和动作图是通过观感来安装的,我想重用一些已经在 ActionMap 中可用的动作.为此,我需要将 ActionMap 条目的键放入 InputMap 条目的值中.

Say I have a standard Swing component like JSlider, but I want to slightly adjust the input map. Default input maps and action map are installed by look and feel, and I want to reuse some of the actions already available in ActionMap. To do that, I need to put ActionMap entry's key into the value of an InputMap's entry.

我可以在运行时使用调试器轻松查找 ActionMap 键(始终为字符串),并重用它.它将工作 - 保证在我的 JDK 和 L&F 版本上.

I can easily look up ActionMap keys (always a String) at runtime with debugger, and reuse it. It will work - guaranteed on my version of JDK and L&F.

所以问题是,默认 Swing 组件操作的键是否记录在任何地方,它们是否可以合法地"随时间变化(即,从 JDK 版本到 JDK 版本或从 L&F 到 L&F)并且您在实践中看到过这样的变化吗?

So the question is, are the keys for default Swing component actions documented anywhere, can they "legally" change over time (that is, from JDK version to JDK version or from L&F to L&F) and have you seen such a change in practice?

谢谢.

推荐答案

好的,我花了一些时间来搜索.

Ok it took me a while to search this up.

简而言之,它们似乎没有(很多)标准化,也没有(很多)被记录下来.

In short, they don't seem to be standarized (much) and they don't see to be documented (much).

LookAndFeel 类是关键.这是层次结构:

The class LookAndFeel is the key. This is the hierarchy:

  • LookAndFeel

  • LookAndFeel

基本外观和感觉

  • MetalLookAndFeel
  • MotifLookAndFeel
  • WindowsLookAndFeel

在 BasicLookAndFeel 类中,您可以找到动作和键绑定的默认映射,所有其他类都会继承这些映射.所以你可以认为这个类是标准.您可以在创建对象默认值"时看到,Java 1.4.2_17 大约为 498.

In the BasicLookAndFeel class, you can find the default mappings for actions and key bindings, which would be inherited by all other classes. So you could consider this class to be the standard. You can see that in the creation of the object "defaults", around like 498 for Java 1.4.2_17.

可以在实现者上找到其他键绑定和覆盖,例如 WindowsLookAndFeel.

Additional key bindings and overwrites can be found on the implementors, such as WindowsLookAndFeel.

一些标准化名称可以在 DefaultEditorKit 类中作为静态字段找到.这些似乎可以安全使用和重新映射.它们的用法可以在 WindowsLookAndFeel 和 MotifLookAndFeel 类中看到.假设这些行为会保持不变,我会感到安全.

Some of the Standarized names can be found on the DefaultEditorKit class as static fields. Those seem to be safe to use and remap. Their usage can be seen in the WindowsLookAndFeel and MotifLookAndFeel classes. I would feel safe assuming that those actions will stay constant.

简而言之,DefaultEditorKit 中定义的 Actions 不太可能改变.但是,L&F 实现之间的键绑定完全不同.使用 DefaultEditorKit.something 从地图中检索操作,它应该可以跨版本工作.您可能会与 JSlider 一起使用的 DefaultEditorAction 示例:

So in short, the Actions defined in DefaultEditorKit are unlikely to change. However, the key bindings change completely between L&F implementations. Retrieve the action from the map using DefaultEditorKit.something and it should work across versions. Example from DefaultEditorAction that you could possibly use with JSlider:

/**
 * Name of the Action for extending the selection
 * by moving the caret logically forward one position.
 * @see #getActions
 */
public static final String selectionForwardAction = "selection-forward";

这篇关于Swing 组件的 ActionMap 中默认操作的名称是否标准化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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