【问题标题】:why doesn't InputMap method directly map keystroke objects to action objects?为什么 InputMap 方法不直接将击键对象映射到动作对象?
【发布时间】:2012-11-15 03:25:27
【问题描述】:

为什么我们必须使用额外的对象ActionMap
什么意思?

以此为例:

imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow");

ActionMap amap = panel.getActionMap();

amap.put("panel.yellow", yellowAction);

【问题讨论】:

    标签: java swing event-handling key-bindings


    【解决方案1】:

    example 所示,InputMapKeyStroke 与标识对应Action 的抽象名称 相关联。 ActionMap 使用该名称作为键来调用特定的Action 实例的actionPerformed() 方法。作为一个具体的例子,这个ScrollTimer 使用ActionMapJScrollPane 来按名称查找动作并使用它们而不直接访问实现。

    附录:抽象旨在支持"pluggable look and feel" (L&F) 架构描述here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      相关资源
      最近更新 更多