在actionPerformed(Java Swing)上单击按钮时,如何识别是否选择了换档? [英] How to recognise if shift is selected when a button is clicked on an actionPerformed (Java Swing)?

查看:114
本文介绍了在actionPerformed(Java Swing)上单击按钮时,如何识别是否选择了换档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在按下JButton的同时按住 Shift 时,我试图创建一个不同的actionPerformed,但是当我使用时: event.isShiftDown; 我的程序无法编译,因为它无法识别.

I'm trying to create a different actionPerformed when Shift is held down while pressing a JButton, but when I use: event.isShiftDown; my program does not compile because it does't recognise it.

推荐答案

基本上,您需要按位运算-并且ActionEvent#getModifiers结果

Basically you need to bitwise-and the ActionEvent#getModifiers result

if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
    // Shift is down...
}

这篇关于在actionPerformed(Java Swing)上单击按钮时,如何识别是否选择了换档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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