如何在Java中进行系统捷径跨平台集成? [英] How to do system short cuts cross platform integration in Java?

查看:113
本文介绍了如何在Java中进行系统捷径跨平台集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您所知,Mac OS X中保存的快捷方式是
Windows上的Cmd + S Ctrl + S ,关闭应用程序的快捷方式是
Cmd + Q ,Windows是 Alt + F4 。但问题是如何在Java应用程序中执行这些操作?我是否需要找到我在应用程序中使用的所有快捷方式,并且匹配相关功能取决于不同的操作系统。有什么建议?谢谢。

As you may know, the short-cuts of save in Mac OS X is Cmd+S on Windows is Ctrl+S, and the short cuts of close an application is Cmd+Q and Windows is Alt + F4. But the question is how to do these in a java application? Do I need to find all the short cuts I used in the application, and match the related function depends on different OSs. Any recommendations? Thanks.

推荐答案

工具包方法 getMenuShortcutKeyMask() 在此上下文中很有用。虽然该方法在Windows上返回 Event.CTRL_MASK ,但它在Mac OS X上返回 Event.META_MASK 。生成的掩码可以用于构造菜单项的 KeyStroke /JMenuItem.html#setAccelerator%28javax.swing.KeyStroke%29rel =noreferrer> setAccelerator() method。

The Toolkit method getMenuShortcutKeyMask() is useful in this context. While the method returns Event.CTRL_MASK on Windows, it returns Event.META_MASK on Mac OS X. The resulting mask can be used to construct the KeyStroke used in a menu item's setAccelerator() method.

这篇关于如何在Java中进行系统捷径跨平台集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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