通过热键执行相应操作时为按钮设置动画
我有与按钮和热键相结合的操作。我想在通过热键触发按钮的相应操作时对按钮进行动画处理(类似于鼠标单击期间显示的动画)。这可能吗?
我正在做如下:
btnAdd.setAction(addDataAction);
panelAdd.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke("ctrl ENTER"), addDataAction);
panelAdd.getActionMap().put(addDataAction, addDataAction);
I have actions coupled with buttons as well as hotkeys. I want to animate(animation similar to the one exhibited during mouse click) the button when its respective action is triggered thru hotkeys. Is that possible?
I am doing as follows:
btnAdd.setAction(addDataAction);
panelAdd.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke("ctrl ENTER"), addDataAction);
panelAdd.getActionMap().put(addDataAction, addDataAction);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我来说很有效(不优雅但有效)
来自 ButtonModel 的 Java API 文档:
This does the trick for me (not elegant but it works)
From the Java API docs for ButtonModel:
请参阅
AbstractButton.setPressedIcon(Icon)
(以及接受Icon
的相关方法)。我们的想法是将非动画图标设置为标准图标,并设置动画 GIF 作为替代图标。See
AbstractButton.setPressedIcon(Icon)
(and related methods that accept anIcon
). The idea would be to set a non-animated icon as the standard icon, and an animated GIF as the alternate.