[英]Which method to choose for adding accelerator to JMenuitem?
I searched the web and found two ways to add an accelerator to a JMenuItem. 我搜索了网络,发现了两种向JMenuItem添加加速器的方法。 Will the choice which one to use have any possible effect on the program?
选择使用哪一个会对程序产生任何影响吗?
menuItem.setAccelerator(KeyStroke.getKeyStroke("control X"););
Or 要么
menuItem.setAccelerator(KeyStroke.getKeyStroke('X', KeyEvent.CTRL_DOWN_MASK));
I would use this one: 我会用这个:
menuItem.setAccelerator(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK);
Because it uses both KeyEvent
constants and you can rely on Java mapping the appropriate character/key. 因为它使用两个
KeyEvent
常量,并且您可以依赖Java映射相应的字符/键。 As a general practice I prefer use constants if available because you can trust on they do what is intended to. 作为一般惯例,我更喜欢使用常量(如果可用),因为您可以信任他们的目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.