Take the 2-minute tour ×

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.

share|improve this question
You'll probably find the answer here: stackoverflow.com/questions/5517674/… –  poplitea Dec 5 '12 at 1:36
add comment

2 Answers

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

if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
    // Shift is down...
share|improve this answer
add comment

As an alternative to checking the event modifiers directly, consider using a different Action for each state of the shift key. You can supply the desired mask to the KeyStroke used in your key binding, as outlined here. A related example using getMenuShortcutKeyMask() is shown here.

share|improve this answer
add comment

Your Answer


